Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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.
Posted 23-Nov-12 1:55am
Edited 23-Nov-12 2:23am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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[^]
  Permalink  
Comments
sravanthi25 at 23-Nov-12 7:36am
   
Thank you for your response. We are tried with the CommandTimeout property. We set to zero.
This fix is for long term or temporary usage.
Because we are not getting this exception very frequently. Can you suggest me that any other solution or this solution is enough.
 
Thanks..
Dominic Abraham at 23-Nov-12 11:36am
   
If the solution is helpful don't forget to mark it as answer. So that it may help others.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

  Permalink  
Comments
Dominic Abraham at 26-Nov-12 1:14am
   
Your issue solved?
sravanthi25 at 26-Nov-12 2:29am
   
Sorry for late replay.
Thank you so much...
My problem is fixed..
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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'.
  Permalink  
Comments
sravanthi25 at 25-Nov-12 23:36pm
   
Thank you for your response. Unfortunatly the above exception is raised while establishing the connection to server [i.e., conn.Open() ] but not from command object.
My code is look like below:
 
SqlCommand cmdSqlCommand = new SqlCommand();

cmdSqlCommand.Connection = Connection; // exception is raised form here. Here
Connection is the Public property.

cmdSqlCommand.CommandType = CommandType.StoredProcedure;

cmdSqlCommand.CommandText = StoredProcedureName;

int result = cmdSqlCommand.ExecuteNonQuery();// exception is not raised from here


//"Connection" Property

public SqlConnection Connection
{
get
{
if (conn == null)
{
string connstr = "server=localhost\SQLEXPRESS;Initial Catalog=MYDB;Integrated Security=True";
conn = new SqlConnection(connstr);
}
 
if (conn.State == System.Data.ConnectionState.Closed)
{
conn.Open();
}

return conn;
}
}
Can you give me the solution.
Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Kornfeld Eliyahu Peter 275
1 Maciej Los 204
2 Sergey Alexandrovich Kryukov 200
3 King Fisher 185
4 OriginalGriff 183
0 OriginalGriff 6,223
1 DamithSL 4,724
2 Maciej Los 4,196
3 Kornfeld Eliyahu Peter 3,894
4 Sergey Alexandrovich Kryukov 3,496


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 25 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100