2

I have a really strange problem with ADOX Interop.

I have this code:

        try
        {
            if (File.Exists(path))
                File.Delete(path);

            var cat = new CatalogClass();
            cat.Create("Provider=Microsoft.Jet.OLEDB.4.0; Data Source = d:\\Test.mdb; Jet OLEDB:Engine Type=5");

            Marshal.ReleaseComObject(cat);
            cat = null;
            GC.Collect();
        }
        catch (FileNotFoundException e)
        {
            throw new FileNotFoundException("El archivo no se encuentra", e);
        }
        catch (COMException e)
        {
            throw new COMException(connStr + e.Message);
        }
        catch (Exception e)
        {
            throw new Exception(connStr, e);
        }

The code is failing in the cat.Create() line. What is really weird is that on my local developer machine it works fine, but in the production server doesn't... It isn't a write permissions problem, because i have tried to generate a random file before the problem line and worked perfectly. The COMException message is only "Not specified Error" HResult: -2147467259

The Server OS is Windows 2008 32bits. I think is a server configuration issue, but can you give me some light? I don't know what else I can do...

HansUp
  • 95,961
  • 11
  • 77
  • 135
Agustin Meriles
  • 4,866
  • 3
  • 29
  • 44
  • Are your target server a x64 machine? Are you targeting your application for AnyCPU? – Steve Apr 09 '12 at 20:39
  • I'm targeting for AnyCPU – Agustin Meriles Apr 09 '12 at 22:00
  • Do you have the same version of ADOX in both computer? – Steve Apr 09 '12 at 22:22
  • Yes, I have copied the same assembly Interop.ADOX.dll but the error persist... This kind of exceptions with no info are really frustrating – Agustin Meriles Apr 09 '12 at 22:27
  • Also have verified the C:\Program Files\Common Files\Microsoft Shared\Dao\ server location, and there is the dao360.dll, as it's expected – Agustin Meriles Apr 09 '12 at 22:30
  • Do you have office installed on your dev machine and not on the server one? If you have Access installed on the server try a VBA version of your code. Sometimes the errore message there are more meaningfull. – Steve Apr 09 '12 at 22:37
  • @HansUp I have undeleted my previous answer because, as you have pointed out, it contains valuable info from an OP comment. Sorry – Steve Apr 10 '12 at 09:06

2 Answers2

3

If you deploy your application on a 64 bit machine your code couldn't use ADOX via JET.OleDB.4.0
If this is the case, then, a fast solution could be to change your target architecture to x86.

Otherwise you could try to download and install on the target machine the 64bit version of Microsoft Access Database Engine drivers, but I don't know if they support ADOX. You will also need to change your connection string

Steve
  • 213,761
  • 22
  • 232
  • 286
2

See whether you can use ADOX Catalog outside your c# code. If you have Access installed, try with Access VBA as Steve suggested. Without Office installed, try with VBScript.

This one works on my 32 bit Windows 7. On 64 bit Windows 7, it fails with an error about "Class not registered". I realize that is not your situation, since you said your server is 32 bit (in reply to an answer which has since been deleted). However my hope is the script will either succeed or give you a more informative error message than you got from the c# error condition.

'Const cPath = "C:\Users\hans\Documents\Test.mdb"
Const cPath = "d:\Test.mdb"
Dim objCat
Dim strConnect
strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=" & cPath & ";Jet OLEDB:Engine Type=5"
WScript.Echo strConnect

Set objCat = CreateObject("ADOX.Catalog")
objCat.Create strConnect
Set objCat = Nothing

I named that file AdoxCreateDb.vbs and ran it with cscript from a command prompt window.

cscript AdoxCreateDb.vbs
HansUp
  • 95,961
  • 11
  • 77
  • 135