The type initializer threw an exception.

  • Thread starter Thread starter JohnZing
  • Start date Start date
J

JohnZing

When i try to open an OleDb connection (access) VS throws the following
error

The type initializer for
'System.Transactions.Diagnostics.DiagnosticTrace' threw an exception.

Tried to find on google and no sucess... please help... thanks

Private Sub OpenConnection()
If _connection Is Nothing Then
_connection = New OleDb.OleDbConnection(_connStr)
_connection.Open()
Else
If _connection.State = ConnectionState.Open Then
Else
_connection.Open()<------- ERRROR HERE
End If
End If
End Sub
 
What makes you think that if the State is not ConnectionState.Open the
connection is closed?
Besides Open there are Connecting, Executing, Fetching or Broken.
You should really test for Connection.Closed instead.
 
Ops, I realized that Executing, Fetching and Broken are reserved for future
versions.
Anyway, why do you need to "open" an already opened connection?
Are you nesting operations?

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/


Miha Markic said:
What makes you think that if the State is not ConnectionState.Open the
connection is closed?
Besides Open there are Connecting, Executing, Fetching or Broken.
You should really test for Connection.Closed instead.

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

JohnZing said:
When i try to open an OleDb connection (access) VS throws the following
error

The type initializer for
'System.Transactions.Diagnostics.DiagnosticTrace' threw an exception.

Tried to find on google and no sucess... please help... thanks

Private Sub OpenConnection()
If _connection Is Nothing Then
_connection = New OleDb.OleDbConnection(_connStr)
_connection.Open()
Else
If _connection.State = ConnectionState.Open Then
Else
_connection.Open()<------- ERRROR HERE
End If
End If
End Sub
 
'System.Transactions.Diagnostics.DiagnosticTrace' exception.

I also struggle with this exception. But finally I got rid of it.
My app.config file was causing this.
Simply remove <configSections> or put it on top. This will solve your problem.:thumb:
 
Back
Top