Getting System.ArgumentNullException for connection in Microsoft.Practices.EnterpriseLibrary.Data Database.cs

Topics: Data Access Application Block
Jul 25, 2009 at 5:47 PM


We're getting the following System.ArgumentNullException intermittently in our WCF service: "Value cannot be null.
Parameter name: connection". Our code calls the LoadDataSet(DbCommand command, DataSet dataSet, string[] tableNames) method in Microsoft.Practices.EnterpriseLibrary.Data Database.cs. We've had app downtime three times in the last week due to this issue and urgently need to get it fixed.

The pattern is always the same: It starts with a random "The SqlTransaction has completed. It is no longer usable." error thrown by our code. I'm guessing this error occurs when a network issue breaks the database connection. Then, for 10-25 minutes, the EntLib is completely unable to connect to the database, throwing the ArgumentNullException each time. After 10-25 minutes, the error clears up by itself. We can fix it earlier by cycling the app pool in IIS.

The issue has occasionally happened before but never with this severity. There may be increased network issues between the server and database, but the EntLib should be able to recover from a dropped connection. Is the bad connection getting cached somehow by EntLib?

Stack trace:

Type : System.ArgumentNullException, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089 Message : Value cannot be null.

Parameter name: connection

Source : Microsoft.Practices.EnterpriseLibrary.Data

Help link :

ParamName : connection

Data : System.Collections.ListDictionaryInternal

TargetSite : Void PrepareCommand(System.Data.Common.DbCommand, System.Data.Common.DbConnection)

Stack Trace :    at Microsoft.Practices.EnterpriseLibrary.Data.Database.PrepareCommand(DbCommand command, DbConnection connection)

at Microsoft.Practices.EnterpriseLibrary.Data.Database.LoadDataSet(DbCommand command, DataSet dataSet, String[] tableNames)

at WebQuote.DataAccess.SqlClient.SqlDatabaseEx.LoadDataSet(DbCommand command, DataSet dataSet, string[] tableNames)

at WebQuote.DataAccess.DbAccess.ExecuteCommand(DbCommand command, DataSet ds)

   at WebQuote.DataAccess.DOQuote.GetChannelAndSalesOrgByCustId(String custId)

   at WebQuote.BusinessLogic.ServiceLibrary.GetChannelAndSalesOrgByCustId(String custId)

Thank you very much in advance,



Jul 25, 2009 at 5:52 PM

I forgot to mention that after the first time this occurred we added code to trap this error and attempt to reset the database connection by calling System.Data.SqlClient.SqlConnection.ClearAllPools();. However, it does not seem to be resolving the issue.

Jul 27, 2009 at 5:17 AM

You said that the pattern is always the same, does this mean that the "The SqlTransaction has completed. It is no longer usable." error first appears then entlib will throw the argumentnullexception? Of you can repro it with exactly the same steps and at exactly the same code? If yes, do you have an executing transaction within that line of code?  DAAB gets the connection of the currently executing transaction if there's one.  If not, it just creates a new one.


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.

Jul 28, 2009 at 2:50 PM

Hi Sarah,

Thanks for your reply - it helped point me in the right direction. It turned out to be custom code in our app that was creating a static instance of the Database object and also caching the current Transaction object. So when the database connection failed and "The SqlTransaction has completed. It is no longer usable." error occurred, the transaction rollback failed but the Transaction remained active with a null connection. That's what was causing the ArgumentNullException errors in the EntLib.


Apr 13, 2015 at 5:22 AM
Hi Ingrid,

This may be so many years. But I got the same problem now you people are facing. I am getting a dead lock when placing an order. So I tried to re-run the tansaction in the catch block . But the Db connection is becoming null and same error that you are facing ... Now i am also facing.... Please help me to get out from this situation.... I will be waiting for ur reply.... If you need clear explantion... I will elobrate and tellu... Its an high priority... Please help me