C# Sqltimeout command don't know program side or sql server side

1

I have a c# program that connects to sql server and get data. This part of program that connects to sql has lots of classes and inheritance that is not written by me and I've never managed to get sqltimeout exceptions from that, which connects to sql server and receives data.

But I have to restart my program and sql timeouts is gone. I don't know is it sql part that locks in storedprocedures or my program locking?

this is the error:

System.Exception: Error In Process 'dbsource' Command In Sequence 1: Error In Run 'dbsource' Command: System.Data.SqlClient.SqlException (0x80131904): Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. ---> System.ComponentModel.Win32Exception (0x80004005): The wait operation timed out at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)

This is some part of sqlconnection class named dbsource:

using (var con = new SqlConnection(setting.ConnectionString))
                    {
                        using (SqlCommand command = new SqlCommand("SET ARITHABORT ON", con))
                        {
                            try
                            {
                                command.CommandText = base.HtmlCommand.Attributes["procedurename"];
                            }
                            catch
                            {
                                if (string.IsNullOrEmpty(setting.ProcedureName))
                                {
                                    command.CommandText = HtmlCommand.HttpContext.CurrentSetting.DEFAULT_ProcedureName;
                                }
                                else
                                {
                                    command.CommandText = setting.ProcedureName;
                                }
                            }

                            var paramsNode = HtmlCommand.TagElements.SingleOrDefault(x => x.TagName == "params");
                            var nameValuePairTblParam = new System.Data.DataTable();
                            nameValuePairTblParam.Columns.Add("name");
                            nameValuePairTblParam.Columns.Add("Value");
                            if (paramsNode != null)
                            {
                                foreach (var node in paramsNode.TagElements)
                                {
                                    try
                                    {
                                        nameValuePairTblParam.Rows.Add(node.GetAttributeValue("name"), node.GetAttributeValue("value", true));
                                    }
                                    catch (Exception ex)
                                    {
                                        throw new Exception("Error in Read Params Section!", ex);
                                    }
                                }
                            }
                            command.CommandType = CommandType.StoredProcedure;
                            StringBuilder sb = new StringBuilder();
                            HtmlCommand.WriteOuterHtml(sb, "params");
                            command.Parameters.Add(new SqlParameter("@c", sb.ToString()));
                            command.Parameters.Add(new SqlParameter("@x", HtmlCommand.HttpContext.Request.DomainId));
                            command.Parameters.Add(new SqlParameter("@y", nameValuePairTblParam));

                            using (SqlDataAdapter adapter = new SqlDataAdapter(command))
                            {                                
                                    adapter.Fill(dataSet);                                                               
                            }
                        }
                    }

There is a RenderingWrapper method that manages sqlConnctions in parallel manner:

private void RenderingWrapper(bool async)
        {
WaitToLoadAllPendingSource(Core, true);
}

protected void WaitToLoadAllPendingSource(string core, bool forIfAttrOnly)
        {
            CheckDataSourcePending(forIfAttrOnly);
            DataSourceAdded();
            if (PendingSource.Count != 0)
            {
                if (OwnerGroup.AllSourceLoaded)
                {
#if DEBUG
                    Util.Log(string.Format("{0:000#} - {1} Stop Process For Not Exist Datasource '{2}' Without Wait...", ID, core, string.Join("','", PendingSource)), ConsoleColor.Red);
#endif
                    return;
                }
#if DEBUG
                Util.Log(string.Format("{0:000#} - {1} Wait Start For '{2}'...", ID, core, string.Join("','", PendingSource)), ConsoleColor.DarkCyan);
#endif
                _waitHandle = new AutoResetEvent(false);
                Thread process = new Thread(() =>
                {
                    while (_waitHandle != null)
                    {
                        Thread.Sleep(1);
                        CheckDataSourcePending(forIfAttrOnly);
                        DataSourceAdded();
                    }
                });

                process.Start();
                _waitHandle.WaitOne(Parent.HttpContext.CurrentSetting.DEFAULT_ExecuteCMSCommandWaitTimeout);
                _waitHandle.Dispose();
                _waitHandle = null;
#if DEBUG
                Util.Log(string.Format("{0:000#} - {1} Wait End.", ID, core), ConsoleColor.DarkCyan);
#endif
                CheckDataSourcePending(forIfAttrOnly);
                DataSourceAdded();
            }
        }

public virtual void DataSourceAdded()
        {
            lock (_check_data_source_lock)
            {

                if (PendingSource != null)
                {
                    foreach (var pendingSource in PendingSource.ToArray())
                    {
                        try
                        {
                            OwnerGroup.GetSource(pendingSource);
                            //check if null
                            //if added by reza
                            if (PendingSource != null)
                                PendingSource.Remove(pendingSource);
                        }
                        catch {/*Nothing*/}
                    }
                }

                if (PendingSource == null || PendingSource.Count == 0)
                {
                    try
                    {
                        if (_waitHandle != null)
                        {
                            _waitHandle.Set();
                        }
                    }
                    catch { /*Nothing*/}
                }
            }
        }


public override void CheckDataSourcePending(bool forIfAttrOnly)
        {
            if (Attributes != null)
            {
                if (forIfAttrOnly)
                {
                    try
                    {
                        var value = Attributes["filter"];
                        Attributes["filter"] = InitalizeStringFromSource(value);
                    }
                    catch {/*Nothing*/ }
                }
                else
                {
                    foreach (var key in Attributes.Keys.ToArray())
                    {
                        try
                        {
                            var value = Attributes[key];
                            Attributes[key] = InitalizeStringFromSource(value);
                        }
                        catch { /*Nothing*/}
                    }
                }
            }
            if (Elements != null && !forIfAttrOnly)
            {
                foreach (HtmlElement child in Elements)
                {
                    child.CheckDataSourcePending(false);
                }
            }
        }
c#
sql-server
timeout
timeoutexception
asked on Stack Overflow Feb 18, 2019 by Hamed_gibago • edited Feb 18, 2019 by Vijunav Vastivch

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0