tags:

views:

54

answers:

2

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?

+2  A: 

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.

ho1
i did the same just creates registry keys but problem with the setting on DSN creation- that is - option as with network login or SQL auttntctn login . i couldn't open reports.
pvaju896
@pvaju896: Not sure if I understand, but if you create a DSN using the Windows tools and then you write the exact same settings straight to the registry using your VB app, won't it work then?
ho1
+1  A: 

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
Driver - Default SQL Server driver path would be "C:\WINDOWS\System32\SQLSRV32.dll"
Server - Your SQL Instance Name Here
Trusted_Connection - Yes or No

Matt
yup u just came to my point..! i've done what you said..!!the PROBLEM--> on creating DSN there's one option.Authenticity type.--> as Network Id login or SQl authenticity.This gives the problem--how can we set that option as sql authentication. otherwise it asks for password on - report loading.
pvaju896
What are you using for your UI? Set your connection string properly if SQL using Initial Catalog for DB, username, pw, etc... What type of report?
Matt