A
aliostad
Has connection pooling implementation changed in .NET 2.0?!
I was happily running a code in 1.1 and now it seems that I have a
problem and receive this error:
System.Data.SqlClient.SqlException : A transport-level error has
occurred when sending the request to the server. (provider: TCP
Provider, error: 0 - An existing connection was forcibly closed by the
remote host.)
The code I am running is a database unit test whereby for every test I
attach my database, run the test and then detach it. Each test, running
on its own works fine. When I run the tests in succession (eg two tests
in the same test fixture by clicking on the test fixture on NUnit GUI)
it fails on the second test with the error above.
The tests open and EXPLICITLY close their connections via a helper
class and never keep any connection open.
Now, when I set pooling=false in my connection string, it runs fine and
now problem at all. To me it seems that .NET 2.0 not only pools the
coonections, but also caches them and since database is restarted,
connection is not valid anymore. If that is the case, this is a major
change from 1.1 and to me it is a bug, even if it is by design. Because
it introduces the potential problem for applications if server is
restarted so they must implement handle an exception that used to be
gracefully handled by pooling itself.
Guys from MS! Could you please shed some light on this?
Here is the trace. I can see a change of implementation from 1.1:
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(TdsParserStateObject
stateObj)
at
System.Data.SqlClient.TdsParserStateObject.ThrowExceptionAndWarning()
at System.Data.SqlClient.TdsParserStateObject.WriteSni()
at System.Data.SqlClient.TdsParserStateObject.WritePacket(Byte
flushMode)
at System.Data.SqlClient.TdsParserStateObject.ExecuteFlush()
at System.Data.SqlClient.TdsParser.TdsExecuteRPC(_SqlRPC[] rpcArray,
Int32 timeout, Boolean inSchema, SqlNotificationRequest
notificationRequest, TdsParserStateObject stateObj)
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 System.Data.SqlClient.SqlCommand.DeriveParameters()
at
System.Data.SqlClient.SqlCommandBuilder.DeriveParameters(SqlCommand
command)
at
DRS.Common.Data.SqlHelperParameterCache.DiscoverSpParameterSet(String
connectionString, String spName, Boolean includeReturnValueParameter,
Object[] parameterValues)
at DRS.Common.Data.SqlHelperParameterCache.GetSpParameterSet(String
connectionString, String spName, Boolean includeReturnValueParameter)
at DRS.Common.Data.SqlHelperParameterCache.GetSpParameterSet(String
connectionString, String spName)
at DRS.Common.Data.SqlHelper.ExecuteReader(String connectionString,
String spName, Object[] parameterValues)
at DRS.Common.Data.SqlHelper.ExecuteEntity(String connectionString,
String spName, Type entityType, Object[] parameterValues)
at DRS.ScriptMarking.WaveData.GetCurrentWave(Int32 ctrId, Int32
comId) in C:\Projects\DRS Products\Script
Marking\Source2\DataLayer\DRS.ScriptMarking.DataLayer.Unit\WaveData.cs:line
20
at DRS.ScriptMarking.WaveDataTest.TestSetWaveAsExported() in
C:\Projects\DRS Products\Script
Marking\Source2\DataLayer\DRS.ScriptMarking.DataLayer.UnitTest\WaveDataTest.cs:line
20
I was happily running a code in 1.1 and now it seems that I have a
problem and receive this error:
System.Data.SqlClient.SqlException : A transport-level error has
occurred when sending the request to the server. (provider: TCP
Provider, error: 0 - An existing connection was forcibly closed by the
remote host.)
The code I am running is a database unit test whereby for every test I
attach my database, run the test and then detach it. Each test, running
on its own works fine. When I run the tests in succession (eg two tests
in the same test fixture by clicking on the test fixture on NUnit GUI)
it fails on the second test with the error above.
The tests open and EXPLICITLY close their connections via a helper
class and never keep any connection open.
Now, when I set pooling=false in my connection string, it runs fine and
now problem at all. To me it seems that .NET 2.0 not only pools the
coonections, but also caches them and since database is restarted,
connection is not valid anymore. If that is the case, this is a major
change from 1.1 and to me it is a bug, even if it is by design. Because
it introduces the potential problem for applications if server is
restarted so they must implement handle an exception that used to be
gracefully handled by pooling itself.
Guys from MS! Could you please shed some light on this?
Here is the trace. I can see a change of implementation from 1.1:
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(TdsParserStateObject
stateObj)
at
System.Data.SqlClient.TdsParserStateObject.ThrowExceptionAndWarning()
at System.Data.SqlClient.TdsParserStateObject.WriteSni()
at System.Data.SqlClient.TdsParserStateObject.WritePacket(Byte
flushMode)
at System.Data.SqlClient.TdsParserStateObject.ExecuteFlush()
at System.Data.SqlClient.TdsParser.TdsExecuteRPC(_SqlRPC[] rpcArray,
Int32 timeout, Boolean inSchema, SqlNotificationRequest
notificationRequest, TdsParserStateObject stateObj)
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 System.Data.SqlClient.SqlCommand.DeriveParameters()
at
System.Data.SqlClient.SqlCommandBuilder.DeriveParameters(SqlCommand
command)
at
DRS.Common.Data.SqlHelperParameterCache.DiscoverSpParameterSet(String
connectionString, String spName, Boolean includeReturnValueParameter,
Object[] parameterValues)
at DRS.Common.Data.SqlHelperParameterCache.GetSpParameterSet(String
connectionString, String spName, Boolean includeReturnValueParameter)
at DRS.Common.Data.SqlHelperParameterCache.GetSpParameterSet(String
connectionString, String spName)
at DRS.Common.Data.SqlHelper.ExecuteReader(String connectionString,
String spName, Object[] parameterValues)
at DRS.Common.Data.SqlHelper.ExecuteEntity(String connectionString,
String spName, Type entityType, Object[] parameterValues)
at DRS.ScriptMarking.WaveData.GetCurrentWave(Int32 ctrId, Int32
comId) in C:\Projects\DRS Products\Script
Marking\Source2\DataLayer\DRS.ScriptMarking.DataLayer.Unit\WaveData.cs:line
20
at DRS.ScriptMarking.WaveDataTest.TestSetWaveAsExported() in
C:\Projects\DRS Products\Script
Marking\Source2\DataLayer\DRS.ScriptMarking.DataLayer.UnitTest\WaveDataTest.cs:line
20