c# - Create SQL Server DSN -


i needing create dsn through code connect sql server. tried example in link, fails datasourcekey never null. have different solution or option?

http://www.codeproject.com/tips/350601/create-sql-dsn-in-csharp

and code:

string odbc_path = "software\\odbc\\odbc.ini\\";      string drivername = "sql server"; string dsnname = "dsnfromcode"; string database = "mydbname"; string description = "this dsn created code!"; //this 1 change made source code had ip of server ,  //am hardcoding server name string server = "brimstone"; bool trustedconnection = false;  // lookup driver path driver name          string driverpath = "c:\\windows\\system32\\sqlsrv32.dll";   var datasourceskey = registry.localmachine.createsubkey(odbc_path + "odbc data sources");          if (datasourceskey == null)  { throw new exception("odbc registry key not exist");  }             datasourceskey.setvalue(dsnname, drivername);               // create new key in odbc.ini dsn name , add values             var dsnkey = registry.localmachine.createsubkey(odbc_path + dsnname);             if (dsnkey == null)  { throw new exception("odbc registry key dsn not created");  }              dsnkey.setvalue("database", database);          dsnkey.setvalue("description", description);          dsnkey.setvalue("driver", driverpath);          dsnkey.setvalue("lastuser", "sa");          dsnkey.setvalue("server", server);          dsnkey.setvalue("database", database); dsnkey.setvalue("username", "sa"); dsnkey.setvalue("password", "system123#"); dsnkey.setvalue("trusted_connection", trustedconnection ? "yes" : "no"); 

i ended exporting registry key pc , launching on loadevent() on pc need it.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -