C# ODBC 连接字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9384311/
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
ODBC ConnectionString
提问by saiful
I have written a program in C# to pull some data using OdbcConnection :
我用 C# 编写了一个程序来使用 OdbcConnection 提取一些数据:
using System.Data.Odbc;
......
OdbcConnection OdbcConn =
new OdbcConnection(Properties.Settings.Default.ConnectionString);
OdbcCommand cmd = new OdbcCommand();
//open connection
if (OdbcConn.State != ConnectionState.Open)
{
OdbcConn.Open();
}
In my settings file, I have this ConnectionString:
在我的设置文件中,我有这个 ConnectionString:
Dsn=****;uid=userID;pwd=password
Dsn=****;uid=userID;pwd=password
However I cannot establish a connection. I have an iseries access driver from IBM corp installed, but if I try MS access then I am able to connect. Any suggestions?
但是我无法建立连接。我安装了 IBM corp 的 iseries 访问驱动程序,但如果我尝试 MS access,则可以连接。有什么建议?
回答by James Hill
When in doubt (and it involves connections strings): http://www.connectionstrings.com/
如有疑问(并且涉及连接字符串):http: //www.connectionstrings.com/
回答by Turbot
I always like to verify the connection using Data source(ODBC) in control panel (assume you are in window environment). Make sure you see the drive available in your ODBC selection and follow the steps to test the connectivity.
我总是喜欢在控制面板中使用数据源(ODBC)来验证连接(假设您在窗口环境中)。确保您在 ODBC 选择中看到可用的驱动器,并按照步骤测试连接。
as also mentioned above the connections strings website would give you idea what properties and format on which particular driver connectivity
如上所述,连接字符串网站会让您了解哪些特定驱动程序连接的属性和格式
回答by Eric Chhun
On a Windows 64 bit machine, make sure you check if your C# code is compiled in x86 (32-bit), x64, or "Any CPU". Note that if you compile as "Any CPU," it'll choose x64 bit drivers by default.
在 Windows 64 位机器上,确保检查您的 C# 代码是否在 x86(32 位)、x64 或“任何 CPU”中编译。请注意,如果您编译为“Any CPU”,它会默认选择 x64 位驱动程序。
The 32-bit drivers can be found at C:\windows\SysWOW64\odbcad32.exe. The 32-bit drivers can be found at C:\windows\system32\odbcad32.exe.
32 位驱动程序可以在C:\windows\SysWOW64\odbcad32.exe 找到。32 位驱动程序可以在C:\windows\system32\odbcad32.exe 找到。
First, make sure you verify your connection works with the ODBC Data Source Administrator using the paths I provided earlier. I.e. make a DSN and test it as Turbot suggested. Once you verified this connection works, your connection string can either use the DSN you just created or you can use a DSN free connection string.
首先,确保您使用我之前提供的路径验证您的连接与 ODBC 数据源管理器一起工作。即制作一个 DSN 并按照 Turbot 的建议进行测试。验证此连接有效后,您的连接字符串可以使用您刚刚创建的 DSN,也可以使用无 DSN 的连接字符串。
For a quick reference, here is a sample of a DSN free connection string using a ODBC driver:
为了快速参考,以下是使用 ODBC 驱动程序的 DSN 自由连接字符串示例:
Driver={Progress OpenEdge 11.3 Driver};HOST=wfdscr11.wf.local;Port=1234;DB=MyDatabaseName;UID=John;PWD=Doe
Driver={Progress OpenEdge 11.3 Driver};HOST=wfdscr11.wf.local;Port=1234;DB=MyDatabaseName;UID=John;PWD=Doe
In this example, I had to connect to a Progress database from my C# code and this is the connection string I used without having to specify a DSN. You can see below that the name of the driver is "Progress OpenEdge 11.3 Driver."
在这个例子中,我必须从我的 C# 代码连接到一个 Progress 数据库,这是我使用的连接字符串,而不必指定 DSN。您可以在下面看到驱动程序的名称是“Progress OpenEdge 11.3 Driver”。


