The type initializer threw an exception.

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
 
M

Miha Markic [MVP C#]

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.
 
M

Miha Markic [MVP C#]

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
 
Joined
Jun 11, 2010
Messages
1
Reaction score
0
'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:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top