超时时间已到。在操作完成之前超时时间已过或服务器未响应。 (.Net SqlClient Data Provider)...

文章详细描述了在使用Visual Studio调试项目后,通过SQL Server Management Studio连接数据库时遇到的超时错误,并提供了多种解决方案,包括修改数据库连接字符串、调整代码中的ConnectionTimeout和CommandTimeout属性、以及修改Web.config文件中的http请求运行时限。最终通过设置适当的超时时间解决了问题。

在做一个小东西的时候出现了这个问题,就是使用VS调试几次项目后,使用SQL Server Management Studio管理数据库时,使用SA登录就会出现这个错误,当然,如果项目中的数据库连接字符串中使用的sa验证,那么项目也会连不到数据库的.可是如果是在 Server Management Studio和项目中使用Windows身份验证,就没有任何问题.
提示错误消息如下


Code
超时时间已到。在操作完成之前超时时间已过或服务器未响应。 (.Net SqlClient Data Provider)

------------------------------
有关帮助信息,请单击: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&EvtSrc=MSSQLServer&EvtID=-2&LinkId=20476

------------------------------
服务器名称: ZY-CQU
错误号: -2
严重性: 11
状态: 0

------------------------------
程序位置:
#region 程序信息
在 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
在 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
在 System.Data.SqlClient.TdsParserStateObject.ReadSniError(TdsParserStateObject stateObj, UInt32 error)
在 System.Data.SqlClient.TdsParserStateObject.ReadSni(DbAsyncResult asyncResult, TdsParserStateObject stateObj)
在 System.Data.SqlClient.TdsParserStateObject.ReadPacket(Int32 bytesExpected)
在 System.Data.SqlClient.TdsParserStateObject.ReadBuffer()
在 System.Data.SqlClient.TdsParserStateObject.ReadByte()
在 System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
在 System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK)
在 System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject)
在 System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart)
在 System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
在 System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
在 System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
在 System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup)
在 System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
在 System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
在 System.Data.SqlClient.SqlConnection.Open()
在 Microsoft.SqlServer.Management.UI.VSIntegration.ObjectExplorer.ObjectExplorer.ValidateConnection(UIConnectionInfo ci, IServerType server)
在 Microsoft.SqlServer.Management.UI.ConnectionDlg.Connector.ConnectionThreadUser()
#endregion 程序信息

初步推断可能是由于我的那个DBAcess类没有正确的关闭数据库连接吧.在网上搜了一通,也没有什么实质性的进展


--------------------------------------------------------------------------------
这里有一个帖子(点我看帖子)反映的情况好像和我的类似,可是他没有说具体的解决方案,仅仅提到优化了一下存储过程

--------------------------------------------------------------------------------
优快云这里有一个类似问题(点我看原文)大意就是说要把TimeOut时间设的长一点,可是我的不是这个原因
初步分析原因为对MSSQL操作时连接超时,知道这事,以前没留意,大概是在配置文件中设置连接时限,在网上找了下解决方法,大多说在数据库连接字符串里解决

SqlConnection con = new SqlConnection("server=.;database=myDB;uid=sa;pwd=password;")
改为:

SqlConnection con = new SqlConnection("server=.;database=myDB;uid=sa;pwd=password;Connect Timeout=500")
似乎没效果。依然运行30秒即报超时!
突然感觉似乎应该可以在连接数据库代码中指明,式了下con的属性,有个ConnectionTimeout,

SqlConnection con = new SqlConnection("server=.;database=myDB;uid=sa;pwd=;");
con.ConnectionTimeout = 180;//报错,属性ConnectionTimeout 为只读!
尝试失败,再接着看command对象属性,发现其也有类似属性!CommandTimeout设置一下:

SqlCommand cmd = new SqlCommand();
cmd.CommandTimeout = 180;
再运行,即解决,这里设置的时间的180秒,即三分钟!可根据需要设置,如果过长,也可以设置为0,当此属性设置为0时表示不限制时间。此属性值应该慎用。还需要在Web.config配置文件中设置http请求运行时限间

<system.web>
<httpRuntime maxRequestLength="102400" executionTimeout="720" />
</system.web>
这里设置的为720秒,前面的属性maxRequestLength一般用于用户上传文件限制大小!默认一般为4096 KB (4 MB)。

解决方法,可以照下图片的步骤来实现。原来值是600秒,改为0即可。

本文来自优快云博客,转载请标明出处:http://blog.youkuaiyun.com/ulark/archive/2010/01/18/5208779.aspx

在做一个小东西的时候出现了这个问题,就是使用VS调试几次项目后,使用SQL Server Management Studio管理数据库时,使用SA登录就会出现这个错误,当然,如果项目中的数据库连接字符串中使用的sa验证,那么项目也会连不到数据库的.可是如果是在 Server Management Studio和项目中使用Windows身份验证,就没有任何问题.
提示错误消息如下


Code
超时时间已到。在操作完成之前超时时间已过或服务器未响应。 (.Net SqlClient Data Provider)

------------------------------
有关帮助信息,请单击: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&EvtSrc=MSSQLServer&EvtID=-2&LinkId=20476

------------------------------
服务器名称: ZY-CQU
错误号: -2
严重性: 11
状态: 0

------------------------------
程序位置:
#region 程序信息
在 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
在 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
在 System.Data.SqlClient.TdsParserStateObject.ReadSniError(TdsParserStateObject stateObj, UInt32 error)
在 System.Data.SqlClient.TdsParserStateObject.ReadSni(DbAsyncResult asyncResult, TdsParserStateObject stateObj)
在 System.Data.SqlClient.TdsParserStateObject.ReadPacket(Int32 bytesExpected)
在 System.Data.SqlClient.TdsParserStateObject.ReadBuffer()
在 System.Data.SqlClient.TdsParserStateObject.ReadByte()
在 System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
在 System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK)
在 System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject)
在 System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart)
在 System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
在 System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
在 System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
在 System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup)
在 System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
在 System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
在 System.Data.SqlClient.SqlConnection.Open()
在 Microsoft.SqlServer.Management.UI.VSIntegration.ObjectExplorer.ObjectExplorer.ValidateConnection(UIConnectionInfo ci, IServerType server)
在 Microsoft.SqlServer.Management.UI.ConnectionDlg.Connector.ConnectionThreadUser()
#endregion 程序信息

初步推断可能是由于我的那个DBAcess类没有正确的关闭数据库连接吧.在网上搜了一通,也没有什么实质性的进展


--------------------------------------------------------------------------------
这里有一个帖子(点我看帖子)反映的情况好像和我的类似,可是他没有说具体的解决方案,仅仅提到优化了一下存储过程

--------------------------------------------------------------------------------
优快云这里有一个类似问题(点我看原文)大意就是说要把TimeOut时间设的长一点,可是我的不是这个原因
初步分析原因为对MSSQL操作时连接超时,知道这事,以前没留意,大概是在配置文件中设置连接时限,在网上找了下解决方法,大多说在数据库连接字符串里解决

SqlConnection con = new SqlConnection("server=.;database=myDB;uid=sa;pwd=password;")
改为:

SqlConnection con = new SqlConnection("server=.;database=myDB;uid=sa;pwd=password;Connect Timeout=500")
似乎没效果。依然运行30秒即报超时!
突然感觉似乎应该可以在连接数据库代码中指明,式了下con的属性,有个ConnectionTimeout,

SqlConnection con = new SqlConnection("server=.;database=myDB;uid=sa;pwd=;");
con.ConnectionTimeout = 180;//报错,属性ConnectionTimeout 为只读!
尝试失败,再接着看command对象属性,发现其也有类似属性!CommandTimeout设置一下:

SqlCommand cmd = new SqlCommand();
cmd.CommandTimeout = 180;
再运行,即解决,这里设置的时间的180秒,即三分钟!可根据需要设置,如果过长,也可以设置为0,当此属性设置为0时表示不限制时间。此属性值应该慎用。还需要在Web.config配置文件中设置http请求运行时限间

<system.web>
<httpRuntime maxRequestLength="102400" executionTimeout="720" />
</system.web>
这里设置的为720秒,前面的属性maxRequestLength一般用于用户上传文件限制大小!默认一般为4096 KB (4 MB)。

解决方法,可以照下图片的步骤来实现。原来值是600秒,改为0即可。

本文来自优快云博客,转载请标明出处:http://blog.youkuaiyun.com/ulark/archive/2010/01/18/5208779.aspx

Category: Microsoft.AspNetCore.Server.IIS.Core.IISHttpServer EventId: 2 SpanId: 260e62075c5affd4 TraceId: 79eb60c3e803fce2e2081624dd324ed3 ParentId: 0000000000000000 RequestId: 4000000e-0008-fd00-b63f-84710c7967bb RequestPath: /webapi/SYStemLoGin/LoGin Connection ID "18230571326760812555", Request ID "4000000e-0008-fd00-b63f-84710c7967bb": An unhandled exception was thrown by the application. Exception: Microsoft.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) ---> System.ComponentModel.Win32Exception (53): 找不到网络路径。 at Microsoft.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) at Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at Microsoft.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnectionString connectionOptions, Boolean withFailover) at Microsoft.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover) at Microsoft.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) at Microsoft.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) at Microsoft.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling, String accessToken, DbConnectionPool pool) at Microsoft.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) at Microsoft.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) at Microsoft.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) at Microsoft.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) at Microsoft.Data.ProviderBase.DbConnectionPool.WaitForPendingOpen() --- End of stack trace from previous location --- at DatabaseMigrationMiddleware.InvokeAsync(HttpContext context) in D:\代码\ZLSL-Project\ZLSLWEBAPI\MyAuthorize\DatabaseMigrationMiddleware.cs:line 44 at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContextOfT`1.ProcessRequestAsync() ClientConnectionId:00000000-0000-0000-0000-000000000000 Error Number:53,State:0,Class:20 还是这个报错信息,我的代码编辑器(vs .net web api)中做迁移没有问题,数据库在我电脑上,别人连我的数据库数据库迁移也没问题,我自己做数据库迁移也没问题,但是发布到iis之后就出这个错误日志
07-16
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值