超时已过期。操作完成之前经过的超时时间或服务器没有响应。 [英] Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

查看:111
本文介绍了超时已过期。操作完成之前经过的超时时间或服务器没有响应。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我们在c#.NET 4.0中使用带有SQL Server 2005的Windows应用程序。我们在建立与SQL服务器的连接时得到了Timeout过期异常。任何人都知道我们为什么会这样做得到这种类型的例外。



Stack Trace如下:

 System.Data.SqlClient .SqlException(0x80131904):超时已过期。操作完成之前经过的超时时间或服务器没有响应。 
在System.Data.SqlClient.SqlInternalConnection.OnError(SqlException异常,布尔breakConnection)
在System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
在System.Data.SqlClient.TdsParserStateObject。 ReadSniError(TdsParserStateObject stateObj,UInt32错误)
at System.Data.SqlClient.TdsParserStateObject.ReadSni(DbAsyncResult asyncResult,TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParserStateObject.ReadNetworkPacket()
at System.Data.SqlClient.TdsParser.ConsumePreLoginHandshake(Boolean encrypt,Boolean trustServerCert,Boolean& marsCapable)
at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo,SqlInternalConnectionTds connHandler,Boolean ignoreSniOpenTimeout,Int64 timerExpire,Boolean encrypt, Boolean trustServerCert,Boolean integratedSecurity)
at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo,String newPassword,Boolean ignoreSniOpenTimeout ,TimeoutTimer超时,SqlConnection owningObject)
在System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo,String newPassword,Boolean redirectedUserInstance,SqlConnection owningObject,SqlConnectionString connectionOptions,TimeoutTimer timeout)
at System.Data.SqlClient .SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject,TimeoutTimer timeout,SqlConnectionString connectionOptions,String newPassword,Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity,SqlConnectionString connectionOptions,Object providerInfo,String newPassword,SqlConnection owningObject ,Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options,Object poolGroupProviderInfo,DbConnectionPool pool,DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConn ection(DbConnection owningConnection,DbConnectionPool池,DbConnectionOptions选项)
at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)
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()



先谢谢。

解决方案

您好


您是否设置了CommandTimeout? 。如果没有,你可以设置CommmandTimeout并检查吗?



以下网址将为您提供有关CommandTimeout的更多信息。



http://msdn.microsoft.com/en-us /library/system.data.sqlclient.sqlcommand.commandtimeout.aspx [ ^ ]


您好



它是不建议将值设置为零。在检查最大查询的执行时间后设置一些值。如果您的最大查询需要10分钟才能执行,请将值设置为600。如果您有1000个查询,并且其中一个查询需要20分钟而所有其他查询需要1分钟,我所做的是将值设置为60并标识特定查询,如果该特定查询将要执行,我将将值设置为'20 * 60'。


您好


您可以查看以下网址。这可能会对你有所帮助。



http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectiontimeout(v = vs.71)的.aspx [ ^ ]

Hi,
We are using windows application in c#.NET 4.0 with SQL server 2005. We got the Timeout expired exception while establishing the connection to the SQL server.Can anyone know the reason why we are getting this type of exception.

Stack Trace is as follows:

System.Data.SqlClient.SqlException (0x80131904): Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
   at System.Data.SqlClient.TdsParserStateObject.ReadSniError(TdsParserStateObject stateObj, UInt32 error)
   at System.Data.SqlClient.TdsParserStateObject.ReadSni(DbAsyncResult asyncResult, TdsParserStateObject stateObj)
   at System.Data.SqlClient.TdsParserStateObject.ReadNetworkPacket()
   at System.Data.SqlClient.TdsParser.ConsumePreLoginHandshake(Boolean encrypt, Boolean trustServerCert, Boolean& marsCapable)
   at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity)
   at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, SqlConnection owningObject)
   at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout)
   at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, TimeoutTimer timeout, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
   at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
   at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
   at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options)
   at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)
   at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)
   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()


Thanks in Advance.

解决方案

Hi
Did you set the CommandTimeout ? . If not can you set the CommmandTimeout and check ?

The below url will give you more information about CommandTimeout.

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.commandtimeout.aspx[^]


Hi

It is not advisable to set the value to zero. You set some value after checking the execution time of your biggest query. If your biggest query takes 10 minutes to execute , set the value to '600'. If you have 1000 queries, and out of that one query takes 20 mints and all others takes 1 mint, what i do is set the value to '60' and identify the particular query, if that particular query is going to execute, i will set the value to '20 * 60'.


Hi
Can you check the below url. This may help you.

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectiontimeout(v=vs.71).aspx[^]


这篇关于超时已过期。操作完成之前经过的超时时间或服务器没有响应。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆