How to Get list of all ODBC or Access DataSources in 64 Bit Machine using C#

171 views Asked by At

My application now supports 64-Bit only and I need to get all the ODBC or Access DataSouces present on the machine or newly created one.

Below code was implemented for fetching the List in 32-bit but now it is crashing on calling the SQLAllocEnv Method.

[DllImport("odbc32.dll")]
private static extern int SQLDataSources(
  int EnvHandle, int Direction, StringBuilder ServerName,
  int ServerNameBufferLenIn, ref int ServerNameBufferLenOut,
  StringBuilder Driver, int DriverBufferLenIn, ref int DriverBufferLenOut);

 [DllImport("odbc32.dll")]
 private static extern int SQLAllocEnv(ref int EnvHandle);

 [DllImport("odbc32.dll")]
 private static extern int SQLFreeEnv(int EnvHandle);

So, Do anyone know how to resolve this ?

1

There are 1 answers

0
Bhupesh On

In some post I found that changing the int dataType to long will work and Yes, it is working in my case also.