none
ADO.NET 2.0 bug? Connection property has not been initialized RRS feed

  • Question

  • Recently, during a project implementation using well tested code, we've been getting this excepting during our calls to the database:

     

    Code Snippet

    System.InvalidOperationException: ExecuteReader: Connection property has not been initialized. ,  
    at System.Data.SqlClient.SqlCommand.ValidateCommand(String method, 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.ExecuteDbDataReader(CommandBehavior behavior) ,  

    at System.Data.Common.DbCommand.ExecuteReader()

     

     

    We've implemented many projects using our database access layer that works by passing DbTransactions objects to newly created objects.  The newly created objects will extract the Connection property from this DbTransaction object for Database connectivity and this model has been working pretty well so far. 

     

    Being baffled by this exception, I did some research and found this blog post from April 6, 2007: http://www.jaxidian.org/update/2007/04/06/7/.  In this post, he reveals that Microsoft acknowledged a bug in ADO.NET 2.0 that will sometimes Garbage Collect the Connection object on a DbTransaction object because for a brief time it has a weak reference to the Connection object.  Most of our projects we build using Debug mode, but this particular project was built in Release mode.  Almost all of the symptoms of the blog post seem to match up pretty well with the symptoms that we are seeing in our case.

     

    EDIT:  I also want to point out that this appears to be happening to random database calls, not to a single query.  The queries that it is happening to have been thouroughly tested and have been running at other client sites for quite some time.

     

    My primary goal of posting is to determine whether this is really an ADO.NET 2.0 bug, or whether I should be investigating the code even further to determine the cause.  Can anyone provide either feedback about this issue or tell me how to find if this is a real ADO.NET bug or not?

     

    Thanks in advance!

     

    Josh

     

    Wednesday, April 23, 2008 12:51 PM

All replies

  • Yes, this is a known bug in System.Data.  It should be fixed in .NET 2.0 SP1, have you tried downloading and testing .NET 2.0 SP1?

     

    Thursday, April 24, 2008 11:11 PM