3

I need to create 32 bit System DSN programitically in Windows 7 OS which is 64 bit. I used the following code.

[DllImport("ODBCCP32.DLL", CharSet = CharSet.Unicode, SetLastError = true)]
private static extern bool SQLConfigDataSource(UInt32 hwndParent, RequestFlags fRequest,string lpszDriver, string lpszAttributes);

public static void CreateDSN() 
{
    string strDrivername = "SQL Server";
    string strConfig = "DSN=test6\0" +
                       "Database=Test\0" +
                       "Description=StackOverflow Sample\0" +
                       "Server=10.10.11.16\0" +                                     
                       "Trusted_Connection=Yes\0";

    bool success = SQLConfigDataSource(0, RequestFlags.ODBC_ADD_SYS_DSN, strDrivername, strConfig);
}

Above code working. but it is creating 64 bit ODBC System DSN. Kindly help me to create 32 bit DSN.

Thanks, Karthik P

Xaruth
  • 4,034
  • 3
  • 19
  • 26
K.P.
  • 105
  • 1
  • 9
  • You are using the 64-bit version of ODBCCP32.DLL. Creating a 32-bit DSN requires using the 32-bit version. Only way to do that is to change your EXE project's Platform target setting to x86. As long as you are hard-coding this, using a simple .reg file is the much simpler solution. – Hans Passant Feb 27 '14 at 13:49

0 Answers0