Internal error of .Net Framework data provider 1

I am developing a WinForm application with Visual Studio 2012 Ultimate with all service packs, C #, and the .NET Framework 4.5.

I get this exception:

Internal .Net Framework Data Provider error 1 

Using this stack:

  en System.Data.ProviderBase.DbConnectionInternal.PrePush(Object expectedOwner) en System.Data.ProviderBase.DbConnectionPool.PutObject(DbConnectionInternal obj, Object owningObject) en System.Data.ProviderBase.DbConnectionInternal.CloseConnection(DbConnection owningObject, DbConnectionFactory connectionFactory) en System.Data.SqlClient.SqlConnection.CloseInnerConnection() en System.Data.SqlClient.SqlConnection.Close() en AdoData.TRZIC.DisposeCurrentConnection() en AdoData.TRZIC.Finalize() 

In the destructor:

 ~TRZIC() { DisposeCurrentConnection(); if (this.getCodeCmd != null) this.getCodeCmd.Dispose(); } private void DisposeCurrentConnection() { if (this.conn != null) { if (this.conn.State == ConnectionState.Open) this.conn.Close(); this.conn.Dispose(); this.conn = null; } } 

I get an exception in the line this.conn.Close(); .

And conn is private SqlConnection conn = null;

Do you know why?

+6
source share
2 answers

I found a solution here: http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/b23d8492-1696-4ccb-b4d9-3e7fbacab846/ .

Mainly:

Attention
Do not call Close or Dispose in Connection, DataReader, or any other managed object in the Finalize method of your class. In the finalizer, you must free the unmanaged resources that your class owns directly. If your class does not own unmanaged resources, do not include the Finalize method in the class definition. See Garbage Collection for more information.

+10
source

This is not an answer, but I highly recommend that you use a connection along this path, and you don’t need to worry about disposing of objects

 using (SqlConnection connection = new SqlConnection(connectionString)) { try { connection.Open(); SqlCommand command = new SqlCommand("......", connection); command.ExecuteNonQuery(); } catch (Exception) { /*Handle error*/ } } 
0
source

All Articles