I am getting "Internal .Net Framework Data Provider error 1" error while calling execute reader.
Any body has idea what is the cause and fix
I am getting "Internal .Net Framework Data Provider error 1" error while calling execute reader.
Any body has idea what is the cause and fix
Internal .Net Framework Data Provider error 1
jwdenny
Failure to observe this rule about closing readers and connections and other managed objects BEFORE Finalize also lead in our case to the following errors:
- "Internal Connection Fatal Error"
Trace Info : 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.ExecuteScalar() at
AND
- "Thread was being aborted"
AND
- "A severe error occurred on the current command. The results, if any, should be discarded."
AND
- "ExecuteScalar requires the command to have a transaction when the connection assigned to the command is in a pending local transaction. The Transaction property of the command has not been initialized."
Basically, it sends IIS and Sql Server AWOL because the connection/reader/transaction has been left open or in an indeterminate state.
In our case it doesn't happen in debug builds only release builds. Now we've removed all the Finalize code and its working fine in release. Two weeks work down the drain investigating this !
And just to make me feel a bit better - heres a sentence from MSDN
"When an object is no longer needed, the CLR calls the Finalize method for that object before freeing its memory. The Finalize method is called a destructor because it performs cleanup tasks, such as saving state information, closing files and connections to databases, and other tasks that must be done before releasing the object."
Exactly what sarah tells us not to do !
Alex Jimenez
JayKay
It's the cpu which hits 100% and I get this weard exception. I changed my machine memory settings and now shows there is available memory at the time of exception and as cpu hits 100% the exception is thrown.
sandPR
I noticed I was having this error a lot when attempting to close a connection. Another thing that I noticed is that the Finalizer was called after the code was finished running and encountered an exception (sometimes after an Assertion failed). To me, this suggests the Finalizer was run at a very weird time (somewhere between when my ASP.NET application stopped and when it was started again). This is all fine and dandy.
How did I fix it I simply open the connection just before I need it, then close it again just after I need it. In my case, I have a factory connection object, then concrete connection objects that inherit from it. They all call the same functions, ExecuteNonQuery, ExecuteScalar, etc.. So in my override methods, I simply open the connection just before my execute, then close it just after.
Vaibhav_Patel
This method is called many times and fails after a long run. I ran task manager and memory is hitting 100% before the error. Though I am not sure, if it is happening due to memory, the errror provide no information to fix the problem.
stack trace :
" at System.Data.ProviderBase.DbConnectionInternal.PrePush(Object expectedOwner)\r\n at System.Data.ProviderBase.DbConnectionPool.PutObject(DbConnectionInternal obj, Object owningObject)\r\n at System.Data.ProviderBase.DbConnectionInternal.CloseConnection(DbConnection owningObject, DbConnectionFactory connectionFactory)\r\n at System.Data.SqlClient.SqlConnection.Close()\r\n at System.Data.SqlClient.SqlDataReader.CloseInternal(Boolean closeReader)\r\n at System.Data.SqlClient.SqlDataReader.Close()\r\n Dispose(Boolean disposing)
Regards,
MARL
i ran into same problem. I'm opening a connection in a class, and trying to close it in Finalize method. I understood what you said here, but could you tell me what's proper event to close a connection inside a class
Thank You.
BarBQ
Could you please give a complete call stack of the exceeption Is the connection still open when you call execute reader
antonio97b
Weird errors like this are often the result of multi-threading access to objects that are not threadsafe. Even if your code is not explicitly creating multiple threads, you have to be careful of situations where multiple threads may be used internally.
I noticed that your call stack shows that the SqlDataReader.Close call is coming from your Finalize method (it's directly coming from Dispose, but Dispose is being called by Finalize). It is not safe to call any managed objects in Finalize, because it is called non-deterministically by the garbage collector on a separate thread. The SqlDataReader.Close documentation explicitly calls this out:
You should explicitly close the SqlDataReader when you are done using it, before finalization. If you do that and are still running into problems, post back again with a new error message and call stack (if they have changed).
Thanks,Sarah