I used a function in ODBCCP32 to create a dsn entry.
The entry was created successfully and could be viewed using odbcca32.exe.
However, when I used regedit and went to HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI, I did not see it there.
This is the function I used:
[DllImport("ODBCCP32.dll")]
private static extern bool SQLConfigDataSource(IntPtr hwndParent, int fRequest, string lpszDriver, string lpszAttributes);
I had a wrap up method to call it:
public static bool CreateDataSource(string ODBC_Driver, string DataSourceName, string DatabasePath)
{
return SQLConfigDataSource((IntPtr)0, ODBC_Request_Modes.ODBC_ADD_SYS_DSN, ODBC_Driver, "DSN=" + DataSourceName);}
The request modes and drivers were declared below:
public static class ODBC_Drivers
{
public static string SQL11 = "SQL Server Native Client 11.0";
}
public static class ODBC_Request_Modes
{
public static int ODBC_ADD_DSN = 1;
public static int ODBC_CONFIGD_DSN = 2;
public static int ODBC_REMOVE_DSN = 3;
public static int ODBC_ADD_SYS_DSN = 4;
public static int ODBC_CONFIG_SYS_DSN = 5;
public static int ODBC_REMOVE_SYS_DSN = 6;
public static int ODBC_REMOVE_DEFAULT_DSN = 7;
}
Note: the program in C# successfully created the dsn entry but it did not write in the registry, as a result, I can not save the credentials there.
Do you see anything flaring at you?
Thanks!