Reputation: 4854
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...
Upvotes: 2
Views: 5404
Reputation: 97131
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
Upvotes: 2
Reputation: 216353
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
Upvotes: 3