Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically configure an ODBC Datasource using C#

Tags:

c#

.net

odbc

Is there any way to create a ODBC DSN with C#?

Maybe a P/invoke?

like image 230
olorin Avatar asked Sep 18 '08 13:09

olorin


People also ask

How do I query ODBC data source?

Connect to an ODBC data source from Power Query Desktop Select the ODBC option in the Get Data selection. In From ODBC, select the data source name (DSN) from the Data source name (DSN) drop-down box. In this example, a DSN name of SQL Server Database was selected. Once you're done, select OK.


2 Answers

You can use Registry classes to write the dsn info in the registry, under

HKLM\Software\ODBC\ODBC.INI\ODBC Data Sources

You'll need to check what values are needed for you ODBC driver.

like image 142
Juanma Avatar answered Sep 17 '22 13:09

Juanma


Following resources might be helpful:

MSDN:

How To Use the ODBC .NET Managed Provider in Visual C# .NET and Connection Strings

CodeProject.com

An ODBC (DSN/Driver) Manager DLL written in C#

You can try to invoke functions:

SQLWriteDSNToIni and ConfigDSN (MSDN links are dead for some reason, try to google by functions names)

like image 42
aku Avatar answered Sep 21 '22 13:09

aku