Reputation: 1417
How can you add a system DSN with its security credentials programmatically at runtime from VB.NET?
Keeping key in ODBC.INI is done, but when creating ODBC, it asks for Authentication Type (SQL or Network Login).
How can we set that option at runtime?
Upvotes: 3
Views: 2933
Reputation: 2088
In VB.NET (assuming this is a 32 bit machine) you want to set that keys at "HKEY_LOCAL_MACHINE\Software\ODBC\ODBC.INI
".
Under there create your ODBC Key if it does not exist and populate the following string values under your key:
Database - Your DB Name here<br />
Driver - Default SQL Server driver path would be "C:\WINDOWS\System32\SQLSRV32.dll"<br />
Server - Your SQL Instance Name Here<br />
Trusted_Connection - Yes or No
Upvotes: 1
Reputation: 55009
It's just registry values. Here's an article from MS about how to do it in VB6, should be very easy to upgrade to VB.Net (the main thing you need the article for will be to see what registry settings etc you need): How To Programmatically Create a DSN for SQL Server with VB
If you haven't used the registry for .Net before, I'd suggest that you start with the RegistryKey class.
Upvotes: 2