The timeout has reached. The timeout has expired or the server has not responded before the operation is completed. (. Net SqlClient Data Provider) (), sqlclientprovider
This problem occurs when you are doing a small task. This error occurs when you use SQL Server Management Studio to manage databases after debugging several projects using, if sa verification is used in the database connection string in the project, the project will not be connected to the database. however, if you use Windows Authentication in Server Management Studio and projects, there is no problem.
The error message is as follows:
Code
The timeout has reached. The timeout has expired or the server has not responded before the operation is completed. (. Net SqlClient Data Provider)
------------------------------
Click: http://go.microsoft.com/fwlink? For help information? ProdName = Microsoft + SQL + Server & EvtSrc = MSSQLServer & EvtID =-2 & LinkId = 20476
------------------------------
ZY-CQU server name
Error code:-2
Severity: 11
Status: 0
------------------------------
Program location:
# Region program information
In System. Data. SqlClient. SqlInternalConnection. OnError (SqlException exception, Boolean breakConnection)
In System. Data. SqlClient. TdsParser. ThrowExceptionAndWarning (TdsParserStateObject stateObj)
In System. Data. SqlClient. TdsParserStateObject. ReadSniError (TdsParserStateObject stateObj, UInt32 error)
In System. Data. SqlClient. TdsParserStateObject. ReadSni (DbAsyncResult asyncResult, TdsParserStateObject stateObj)
In System. Data. SqlClient. TdsParserStateObject. ReadPacket (Int32 bytesExpected)
In System. Data. SqlClient. TdsParserStateObject. ReadBuffer ()
In System. Data. SqlClient. TdsParserStateObject. ReadByte ()
In System. Data. SqlClient. TdsParser. Run (RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
In System. Data. SqlClient. SqlInternalConnectionTds. CompleteLogin (Boolean enlistOK)
In System. Data. SqlClient. SqlInternalConnectionTds. AttemptOneLogin (ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject)
In System. Data. SqlClient. SqlInternalConnectionTds. LoginNoFailover (String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart)
In System. Data. SqlClient. SqlInternalConnectionTds. OpenLoginEnlist (SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
In System. Data. SqlClient. SqlInternalConnectionTds. TDS (DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
In System. Data. SqlClient. SqlConnectionFactory. CreateConnection (DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
In System. Data. ProviderBase. DbConnectionFactory. CreateNonPooledConnection (DbConnection owningConnection, DbConnectionPoolGroup poolGroup)
In System. Data. ProviderBase. DbConnectionFactory. GetConnection (DbConnection owningConnection)
In System. Data. ProviderBase. DbConnectionClosed. OpenConnection (DbConnection outerConnection, DbConnectionFactory connectionFactory)
In System. Data. SqlClient. SqlConnection. Open ()
In Microsoft. SqlServer. Management. UI. VSIntegration. ObjectExplorer. ObjectExplorer. ValidateConnection (UIConnectionInfo ci, IServerType server)
In Microsoft. SqlServer. Management. UI. ConnectionDlg. Connector. ConnectionThreadUser ()
# Endregion program information
It may be because my DBAcess class didn't close the database connection correctly. I searched the internet and there was no substantial progress.
--------------------------------------------------------------------------------
Here is a post (click here to view the post) that reflects the situation similar to mine, but he did not mention the specific solution, just mentioned that the storage process has been optimized
--------------------------------------------------------------------------------
CSDN has a similar problem here (Click here to see the original article). The general idea is to set the TimeOut time a little longer, but I am not responsible for this.
The initial analysis reason is that the connection timed out during the MSSQL operation. I did not pay attention to this issue before, probably because I set the connection time limit in the configuration file and found a solution online, most of them are solved in database connection strings.
SqlConnection con = new SqlConnection ("server =.; database = myDB; uid = sa; pwd = password ;")
Changed:
SqlConnection con = new SqlConnection ("server =.; database = myDB; uid = sa; pwd = password; Connect Timeout = 500 ")
It seems ineffective. If it is still running for 30 seconds, a timeout is reported!
Suddenly, it seems that you can specify the con attribute in the database connection code. There is a ConnectionTimeout,
SqlConnection con = new SqlConnection ("server =.; database = myDB; uid = sa; pwd = ;");
Con. ConnectionTimeout = 180; // an error is reported. The ConnectionTimeout attribute is read-only!
The attempt failed, and then looked at the command object property, and found that it also has a similar property! CommandTimeout settings:
SqlCommand cmd = new SqlCommand ();
Cmd. CommandTimeout = 180;
Run again to solve the problem. The time set here is 180 seconds, that is, three minutes! You can set it as needed. If it is too long, you can also set it to 0. When this attribute is set to 0, there is no time limit. This attribute value should be used with caution. You also need to set the time limit for running http requests in the Web. config configuration file.
<System. web>
<HttpRuntime maxRequestLength = "102400" executionTimeout = "720"/>
</System. web>
The value is set to 720 seconds. The preceding maxRequestLength attribute is generally used to limit the size of uploaded files! The default value is generally 4096 KB (4 MB ).
The solution can be achieved through the photo steps. The original value is 600 seconds. Change it to 0.
This article from the CSDN blog, reproduced please indicate the source: http://blog.csdn.net/ulark/archive/2010/01/18/5208779.aspx
Ps: I am a newbie and have little knowledge about SQL optimization. I hope you can recommend some blogs on SQL optimization!