C# 重复堆栈跟踪意味着什么?
我有一个webservice和一个webmethod,它可以在设定的时间间隔异步调用,也可以根据不同的因素随机调用(这基本上意味着它可以在任何时候被多个东西调用)。此webmethod在其主体内多次调用数据库。我有时会收到超时、死锁和其他需要进行各种改进的迹象。但这并不是很相关。我想问的是这个堆栈跟踪:C# 重复堆栈跟踪意味着什么?,c#,.net-2.0,stack-trace,sqlexception,C#,.net 2.0,Stack Trace,Sqlexception,我有一个webservice和一个webmethod,它可以在设定的时间间隔异步调用,也可以根据不同的因素随机调用(这基本上意味着它可以在任何时候被多个东西调用)。此webmethod在其主体内多次调用数据库。我有时会收到超时、死锁和其他需要进行各种改进的迹象。但这并不是很相关。我想问的是这个堆栈跟踪: System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to complet
System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
at MyWebservice.PrivateMethod()
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
at MyWebservice.PrivateMethod()
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
at MyWebservice.PrivateMethod()
at MyWebservice.WebMethod()
注意事项:
using SqlConnection connection = new SqlConnection(connectionString)
{
SqlCommand command = new SqlCommand("SP name here", connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("@paramName", _param);
// several other parameters added the same way here
SqlParameter result = new SqlParameter();
result.ParameterName = "@result";
result.DbType = DbType.Boolean;
result.Direction = ParameterDirection.Output;
command.Parameters.Add(result);
connection.Open();
command.ExecuteNonQuery();
try { _spresult = (bool)result.Value; }
catch (InvalidCastException) { return true; } // this is by design, please don't pester me about it
return _spresult;
}
如果WebMethod的一个参数设置为true,则在WebMethod的一开始就调用它,否则根本不会调用它
编辑2:忘了提到,它是.NET2.0。不知道这是否重要。这应该可以解决线程问题 将静态lockObj添加到类中
var isIdle = true;
if (isIdle)
{
lock (padlock)
{
if (isIdle)
{
isIdle = false;
using SqlConnection connection = new SqlConnection(connectionString)
{
SqlCommand command = new SqlCommand("SP name here", connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("@paramName", _param);
// several other parameters added the same way here
SqlParameter result = new SqlParameter();
result.ParameterName = "@result";
result.DbType = DbType.Boolean;
result.Direction = ParameterDirection.Output;
command.Parameters.Add(result);
connection.Open();
command.ExecuteNonQuery();
try { _spresult = (bool)result.Value; }
catch (InvalidCastException) { return true; } // this is by design, please don't pester me about it
}
}
}
}
return _spresult;
}
你能发布方法内容和调用它的方法吗?哪个方法?PrivateMethod在WebMethod的一开始就被调用,它只不过是一个标准——使用SqlConnection、声明和定义SqlCommand、添加参数、打开连接、执行非查询、返回结果。真的有必要显示准确的代码吗?发布调用它的内容可能更重要。我想不出任何与多线程代码相关的东西会导致像这样奇怪的堆栈跟踪,我想看看代码,看看是否有一个微妙的原因,你可能会丢失。你如何获得这个堆栈跟踪?这是您在调试器的异常详细信息中看到的,还是您从任何日志中读取的内容?@AdamHouldsworth what调用WebMethod?据我所知,它是一个简单的控制台应用程序,用于调用各种数据集,并为集合中的每一项调用WebMethod。但我不知道该应用程序是如何使用的。