yo3hcv
yo3hcv

Reputation: 1669

What is the odbcjt32.dll real path, System32 or SysWOW64 to check it's parameters

I'm trying to create a ODBC connection programmatic, via registry.

When using Windows ODBC tool, I noticed that for ODBC 32, "Microsoft Access Driver (*.mdb)" is using odbcjt32.dll and the entry in registry would point to this location:

"Driver"="C:\\Windows\\system32\\odbcjt32.dll"

But when I search for the file, it exists, but is located in other folder:

C:\Windows\SysWOW64

I need to know why because:

There is a magic redirection for this DLL in Windows ?

Thanks for clarification,

Upvotes: 0

Views: 2564

Answers (2)

Albert D. Kallal
Albert D. Kallal

Reputation: 48989

But why create a DSN?

You can do this:

string MyCon = "Driver={Microsoft Access Driver (*.mdb, *.accdb)};dbq=C:\\Test2\\test44.accdb";
DataTable MyTable = new DataTable();
OdbcDataAdapter MyData = new OdbcDataAdapter("select * from tblHotels", MyCon);
MyData.Fill(MyTable);

MessageBox.Show("Records = " + MyTable.Rows.Count.ToString() );

We only need:

using System.Data;
using System.Data.Odbc;

I mean, your utility might be wanting to create a DSN, but if you just looking to create a connection, then the above is fine. As long as ACE32, or ACE 64 bit version is installed, then this will work.

Note that odbcjt32.dll is a x32 bit ONLY component. You will never find or see a x64 bit version - it don't exist. And installing ACE x64 will not install that .dll either.

However, it not clear why you need to create the DSN connection as opposed to having a setting in your application (or some setup file) that simply has the above connection string? Attempting to create a DSN will often require elevated rights, but in place of the DSN you can use a simple connection string for ODBC as per above. There is no speical references required for the above code snip to work - it just uses the ODBC parts built into the net framework.

Upvotes: 1

Marius
Marius

Reputation: 1679

See the super user question "System32 and SysWOW64 on Windows 7" for some background info on SysWoW64 and system32. So yes, there is a "magic redirection" on windows for 32 bit and 64 bit DLLs.

The file odbcjt32.dll in C:\Windows\SysWOW64 is a 32 bit version. The path C:\Windows\system32\ is redirected to C:\Windows\SysWOW64\ for a 32 bit program. What is the current solution platfrom of your program? x86, x64 or Any CPU? I think it should be x86 so that it can use the 32 bit driver.

Take a look at Environment.GetFolderPath method with Environment.SpecialFolder.SystemX86 so that you do not need to hardcode the path.

Additional info on the magic redirection

To see the bitness of a DLL you can use dumpbin.I use "odbc32.dll" in my examples below. Open the Developer Command Prompt of your Visual Studio version and execute the following command:

dumpbin /headers c:\windows\syswow64\odbc32.dll

The output will contain the following line:

FILE HEADER VALUES
             14C machine (x86)

Now execute dumpbin for the DLL in the system32 directory:

dumpbin /headers c:\windows\system32\odbc32.dll

which outputs

FILE HEADER VALUES
            8664 machine (x64)

As you can see there is a x64 ("64 bit") and a x86 ("32 bit") version of the same DLL on the machine. Windows does the magic redirection depending on the bitness of the program that is running. A 64 bit program gets the DLL from C:\Windows\system32 and a 32 bit program gets it from C:\Windows\SysWoW64.

Upvotes: 2

Related Questions