9

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

Maybe a P/invoke?

olorin
  • 2,214
  • 3
  • 19
  • 22

3 Answers3

2

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.

Juanma
  • 3,961
  • 3
  • 27
  • 26
1

An example of the Registry Keys and Values required to create an ODBC Data Source for SQL Server can be found here.

Community
  • 1
  • 1
Matthew Murdoch
  • 30,874
  • 30
  • 96
  • 127
1

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)

aku
  • 122,288
  • 32
  • 173
  • 203