ODBC 连接字符串
我用 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();
}
在我的设置文件中,我有这个 ConnectionString:
Dsn=****;uid=userID;pwd=password
但是我无法建立联系。我安装了 IBM 公司的 iseries access 驱动程序,但如果我尝试 MS access,则可以连接。有什么建议吗?
I have written a program in C# to pull some data using 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:
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如有疑问(并且涉及连接字符串):http://www.connectionstrings.com/
When in doubt (and it involves connections strings): http://www.connectionstrings.com/
在 Windows 64 位计算机上,请确保检查 C# 代码是否在 x86(32 位)、x64 或“任何 CPU”中编译。请注意,如果您编译为“任何 CPU”,它将默认选择 x64 位驱动程序。
32 位驱动程序位于 C:\windows\SysWOW64\odbcad32.exe。 32 位驱动程序位于 C:\windows\system32\odbcad32.exe。
首先,请确保使用我之前提供的路径验证 ODBC 数据源管理器的连接是否正常。即创建一个 DSN 并按照 Turbot 的建议进行测试。验证此连接有效后,您的连接字符串可以使用刚刚创建的 DSN,也可以使用不依赖 DSN 的连接字符串。
为了快速参考,下面是使用 ODBC 驱动程序的 DSN 免费连接字符串的示例:
在此示例中,我必须从 C# 代码连接到 Progress 数据库,并且此是我使用的连接字符串,无需指定 DSN。您可以在下面看到驱动程序的名称是“Progress OpenEdge 11.3 Driver”。
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.
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.
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.
For a quick reference, here is a sample of a DSN free connection string using a ODBC driver:
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."
我总是喜欢使用控制面板中的数据源(ODBC)来验证连接(假设您在窗口环境中)。确保您在 ODBC 选择中看到可用的驱动器,并按照步骤测试连接。
如上所述,连接字符串网站会让您了解特定驱动程序连接的属性和格式
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.
as also mentioned above the connections strings website would give you idea what properties and format on which particular driver connectivity