Can anybody give me an example of how to create a DSN in code using SQLConfigDataSource please.
Banging my head against a brick wall!! :mad:
Printable View
Can anybody give me an example of how to create a DSN in code using SQLConfigDataSource please.
Banging my head against a brick wall!! :mad:
Hi,
I use this code to create a DSN... you can control if it is a user or system dsn by opening the Registry.LocalMachine or Registry.CurrentUser methods respectively. All I did to check this was create a DSN, look at what happens in the registry, then take each value from the registry and ensure that the code below actually populates the registry with the relevant information.
Also, I think you need to include the Microsoft.Win32.Registry or something like that at the top of your code.
Hope this helps?Code:RegistryKey r = Registry.LocalMachine.CreateSubKey("SOFTWARE\\ODBC\\ODBC.INI\\DSN NAME");
r.SetValue("BufferSize","65535");
r.SetValue("Description","Connection");
r.SetValue("Driver","C:\\Windows\\System32\\msorcl32.dll");
r.SetValue("DSN","DSN NAME");
r.SetValue("GuessTheColDef","0");
r.SetValue("PWD","");
r.SetValue("Remarks","0");
r.SetValue("SERVER","oracleserver");
r.SetValue("StdDayOfWeek","1");
r.SetValue("StripTrailingZero","0");
r.SetValue("SynonymColumns","1");
r.SetValue("UID","me");
r.Close();
r = Registry.LocalMachine.OpenSubKey("SOFTWARE\\ODBC\\ODBC.INI\\ODBC Data Sources\\",true);
r.SetValue("DSN NAME","Microsoft ODBC for Oracle");
r.Close();
DJ