Accessing ODBC DSNs

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Way back in the old ASP days, it was possible to open a Database connection
by providing only the name of the ODBC DSN that I'd created earlier. I didn't
need to indicate which driver, whether the connection was to SqlServer or
something else, etc. It looked like:

Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "MyNamedDSN"

In C#.Net, I'm trying to figure out what connection string I provide when I do
Conn = new OleDbConnection(ConnString);

if I want to connect via an ODBC DSN instead of specifying the details in
the ConnectionString itself. Can you help with this?

Thanks.

Alex
 
Hello Alex,

DSN's only work with ODBC (since they aren't OLEDB). So change your provider
to OdbcProvider and use your old connection string and it will work:

Conn = new OdbcConnection(ConnString)


Thanks,
Shawn Wildermuth
Speaker, Author and C# MVP
http://adoguy.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top