SQL connection timeout after 100 minutes
bgraves
Posts: 19
I'm trying to do a data compare on a single table between 2 servers. This runs every hour and works most of the time. However, every couple of days I consistently get the following error (after 6002 seconds) until I restart the destination SQL server:
Exception: System.Exception: Unable to setup databases for replication. Internal error:
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.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlDataReader.SetMetaData(_SqlMetaDataSet metaData, Boolean moreInfo)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader()
at j.j(SqlConnection )
at j.a()
at RedGate.SQLCompare.Engine.Database.RegisterForDataCompare(ConnectionProperties connectionProperties, Options options)
at RedGate.SQLCompare.Engine.Database.RegisterForDataCompare(ConnectionProperties connectionProperties)
Any idea why this could be happening?
Exception: System.Exception: Unable to setup databases for replication. Internal error:
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.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlDataReader.SetMetaData(_SqlMetaDataSet metaData, Boolean moreInfo)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader()
at j.j(SqlConnection )
at j.a()
at RedGate.SQLCompare.Engine.Database.RegisterForDataCompare(ConnectionProperties connectionProperties, Options options)
at RedGate.SQLCompare.Engine.Database.RegisterForDataCompare(ConnectionProperties connectionProperties)
Any idea why this could be happening?
Comments
Thanks for your post. Generally, when we have seen this before it relates to a problem with connectivity on the host machine which would explain why a reboot resolves the issue.
Out of curiosity, how large is the data set in those tables?
Pete
Red Gate Software Ltd
+44 (0)870 160 0037 ext. 8569
1 866 RED GATE ext. 8569
What connectivity problem are you referring to?
Connectivity problem is this:
See also, which refers to it either being a timeout on the query or network connectivity:
http://stackoverflow.com/questions/810673/connection-problems-with-sql-server-in-asp-net-applications-using-out-of-process
You can add a connection timeout value in the server name that you are connecting to within the batch file, i.e.:
It could be very well the the timeout if the connection is particularly slow between these machines. Maybe try increasing the timeout to 20 minutes to see if that helps.
Pete
Red Gate Software Ltd
+44 (0)870 160 0037 ext. 8569
1 866 RED GATE ext. 8569
How long does the process normally take? Is it close to the 100 minutes usually, or does it normally complete in, say, 10 minutes?
When it fails do you see any messages in the SQL Server error log at all?
Redgate Software
The process usually takes 6-25 seconds unless we get these 100 minute connection timeouts. It's always happening on a single table. The only messages in the SQL Server error log is the "Log was backed up" message that occurs every hour on the hour. Otherwise, I'm getting these timeout exception consistently throughout the night (no select is taking place...so it looks like the connection is timing out!) until it starts working again early in the morning:
Exception: System.Exception: Unable to setup databases for replication. Internal error:
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.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlDataReader.SetMetaData(_SqlMetaDataSet metaData, Boolean moreInfo)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader()
at j.j(SqlConnection )
at j.a()
at RedGate.SQLCompare.Engine.Database.RegisterForDataCompare(ConnectionProperties connectionProperties, Options options)
at RedGate.SQLCompare.Engine.Database.RegisterForDataCompare(ConnectionProperties connectionProperties)
Given that it fails after the 6000 period, it seems more like it's the command itself that's timing out for some reason; possibly because it's being blocked by some other process. This would make sense if restarting the SQL Service then gets it going again. Of course, working out what that is is the tricky part. You could try running sp_who2 to see if that lists other active processes against the DB in question? That may help...
Redgate Software
Yes, I have used the sp_who2 and no sysprocesses are getting blocked when this is happening. However, there is no redgate SYSPROCESS to BLOCK anyway (unusual since there is always one running when everything is working correctly) during the period before the timeout eventually occurs. Again there is no select command that can get timed out since there is no redgate sysprocess running...so what does this exception mean anyway?
Anyway, it sounds like changing the connection timeout to 20 minutes will have no effect since the timeout occurs after 100 minutes. Correct?
I don't see anywhere that we set the connection timeout, so I have to assume it uses the default value that .NET uses with the SQLConnection - for instance, try connecting in the GUI to a non-existent server. It failed after a couple of minutes for me, rather than the 100 minutes you see which suggests that the it may not be the initial connection that's timing out.
But then as you point out, if you don't see any Redgate process that would suggest more that it is indeed the connection that's timing out rather than the command execution. So it's a tricky one to pinpoint.
If it normally takes just a few seconds to run, then I'm not sure whether increasing the timeout will help - even if you set it to say, 2 hours, I'm guessing it would sit for that long before failing; but working out why the connection can't be established is tricky- it may be worth trying a longer timeout as a simple test (maybe 7200?), but if that still doesn't help, I'm not sure what the next step would be....
Redgate Software
So, if it's that part that's failing, then it won't be the command, it will be the connection timeout.
There's not much that can be done in the application to get around that- if increasing the timeout doesn't help then for whatever reason, the server isn't accepting the connection and never will.
Once it is timing out, can you connect using SSMS from the same place you run Data Compare?
Redgate Software
Redgate Software
Although I can't spot anything specifically affecting your version, it's probably worth you upgrading to the latest version to see if the problem persists, just in case there was a problem with connections being held open in your version.
Redgate Software
Unfortunately it's not possible to sync just certain aspects of an object. You can ignore Indexes from beign compared and synced (the GUI has a tickbox option for this, and I'm sure there's an equivalent option in the SDK) but asides from that the sync operates on the whole table object.
Redgate Software