views:

48

answers:

2

Ok so this is a really complicated problem, I will try my best to explain.

We have a c++ application which communicates with Sql Connection like so:

CoCreateInstance(_T("ADODB.Connection"))

This works fine.

We recently made all of our backend code into a Com Object. If I write a Vb program to load our Com Object and do some database operations everything works fine, CoCreateInstance(_T("ADODB.Connection"))
still works.

We use fitnesse for testing so I wrote a fixture that:
1) Takes a string of vb code input into an html page.
2) compiles the vb code
3) runs the vb code that uses our Com Object.
* fitnesse is a java application so the code path travels through Java as well.

Now when any operation touches the database the Com Object hits an exception. Uses message boxes, and removing code I narrowed the problem down to this line of code:

CoCreateInstance(_T("ADODB.Connection"))

normally the return code is 0, but with this chain of code calling code I get the return code: 800401F3 which says that it cannot find the object to load.

I am pulling my hair out trying to figure out whats going on. Any bit of insight would be greatly appreciated.

+1  A: 

It is telling you that it cannot find the ProgId in the registry. That's not very healthy, it is a pretty standard component on any Windows install. Verify this, fire up regedit.exe and navigate to HKLM\Software\Classes\ADODB.Connection

If that is missing then you need to install the dbase providers on that machine. Download the MDAC 2.8 installer from Microsoft and run it. If it is not missing then you have a more mysterious problem, perhaps something to do with this being a 64-bit operating system. Look in HKLM\Software\Wow6432Node then. Get additional diagnostics by using the SysInternals' ProcMon tool to see what it is poking at in the registry.

Hans Passant
It exists in the registry, and it allows me to create it in all but the very specific scenario I hopefully explained well.
Joshua Jewell
So, what did ProcMon tell you?
Hans Passant
Not quite sure how I should be using the ProcMon tool, Should I see what tries to access the registry as I run my code?
Joshua Jewell
I'll give you an answer in a couple of hours to give you a chance to start it.
Hans Passant
When 'FitserverDotNet.exe' tried to access the registry key 'HKCU\Software\Classes\ADODB.Connection' I get a 'BAD IMPERSONATION' resultThe Com Api does do impersonation since its used in an IIS Web Service.
Joshua Jewell
If I undo the impersonation the problem is solved, THANKS!
Joshua Jewell
Well, that was a happy ending :)
Hans Passant
I still don't understand exactly why it was a bad impersonation since it worked in so many other scenarios. However I have learned that I don't need to know every little detail! Thanks again for your help, would not have solved it without using ProcMon.
Joshua Jewell
+1  A: 

As an alternative, you don't say whether your com "object" is a .dll. If it is, then make sure it is either "self-registering" or you'll need to run this at the command prompt.

regsvr32 myobject.dll

If it's an exe with COM objects, register the objects by running the program with the "/RegServer" command line option like this:

myobject.exe /RegServer

HTH

JustBoo
Hey the Com object is a dll and has been registered with regsvr32 myobject.dll.I also added it to the .net project as a reference.
Joshua Jewell