如何使用 C# 以编程方式配置 ODBC 数据源
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/92514/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to programmatically configure an ODBC Datasource using C#
提问by olorin
Is there any way to create a ODBC DSN with C#?
有没有办法用C#创建一个ODBC DSN?
Maybe a P/invoke?
也许是 P/调用?
回答by aku
Following resources might be helpful:
以下资源可能会有所帮助:
MSDN:
微软:
How To Use the ODBC .NET Managed Provider in Visual C# .NET and Connection Strings
如何在 Visual C# .NET 和连接字符串中使用 ODBC .NET 托管提供程序
CodeProject.com
CodeProject.com
An ODBC (DSN/Driver) Manager DLL written in C#
用 C# 编写的 ODBC(DSN/驱动程序)管理器 DLL
You can try to invoke functions:
您可以尝试调用函数:
SQLWriteDSNToIni and ConfigDSN (MSDN links are dead for some reason, try to google by functions names)
SQLWriteDSNToIni 和 ConfigDSN(MSDN 链接由于某种原因已失效,请尝试按函数名称搜索)
回答by Juanma
You can use Registry classes to write the dsn info in the registry, under
您可以使用注册表类在注册表中写入 dsn 信息,在
HKLM\Software\ODBC\ODBC.INI\ODBC Data Sources
You'll need to check what values are needed for you ODBC driver.
您需要检查 ODBC 驱动程序需要哪些值。