tags:

views:

94

answers:

1

I have an OLE DB connection in VB.NET that I am trying to use to connect to an Oracle database. However, I get the following error on the con.Open() line:

LoaderLock was detected

Attempting managed execution inside OS Loader lock. Do not attempt to run managed code inside a DllMain or image initialization function since doing so can cause the application to hang.

Here is my code:

Dim con As New OleDb.OleDbConnection

ConfigConnection()

Try
 con.ConnectionString = ConnectionString
Catch ex As Exception
 MsgBox("Invalid connection string)
 Return
End Try

Try
 con.Open()
 MsgBox("Connection attempt successfull!")
Catch ex As Exception
 MsgBox("Unable to connect to data source.")
End Try

I use this same code to connect to various other types of databases, including SQL Server, Excel, and Access. When connecting to any of those it connects successfully and I don't get this error.

I am executing this code within a dll. If I execute it within an exe it works fine. However, I need to execute this within this dll.

+1  A: 

It's a debugger assistant warning, so if you test your code and find it works fine, you may not need to worry about it.

I've seen a similar thing when calling DirectX, but following all the suggestions on the net to eliminate the error made no difference - the code you're calling still does whatever naughty thing it shouldn't be doing. Having put in a lot of effort trying to eliminate it, and yet not seen a single problem caused by it after 2 years, I filed it in my "just ignore this irritating warning" bin.

You can suppress the warning by going to Debug -> Exceptions. Click the Find button and type LoaderLock, then untick it.

BUT this advice only applies IF you have thoroughly tested your application and are absolutely sure that the application never fails because of the LoaderLock. And then it's at your discretion as to whether you are happy to release your program with this potential problem in it.

Perhaps somebody else will be able to supply a better solution though - I always feel rather uneasy about ignoring this type of warning.

Jason Williams