简体   繁体   English

如何在C#应用程序中使用DSN文件?

[英]How to use a DSN file in a C# application?

This is my old code. 这是我的旧代码。

conn = new System.Data.Odbc.OdbcConnection();
conn.ConnectionString = @"DSN=dBase Files";

It throws an Error: (I think my old code might still work on 32 bit machines, but I am on 64 now) 它抛出一个错误:(我想我的旧代码可能仍然可以在32位机器上运行,但我现在在64)

"[Error] [IM002] [Microsoft] [ODBC Driver Manager] Data source name not found and no default driver specified"

All my searches told me to use SysWow64/odbcad32.exe to create a .DSN file. 我的所有搜索都告诉我使用SysWow64 / odbcad32.exe来创建.DSN文件。 Now I created the DSN file, How can I modify this line, conn.ConnectionString = @"DSN=dBase Files"; 现在我创建了DSN文件,如何修改此行, conn.ConnectionString = @"DSN=dBase Files"; , to point to the .DSN file I saved on disk? ,指向我保存在磁盘上的.DSN文件?

As far as I recall, I had to set up the DSN in ODBC Data Sources under Administrative Tools, but that was around the turn of the century. 据我所知,我必须在管理工具下的ODBC数据源中设置DSN,但那是在世纪之交。

This might help: FILEDSN=c:\\myDsnFile.dsn;Uid=myUsername;Pwd=; 这可能会有所帮助: FILEDSN=c:\\myDsnFile.dsn;Uid=myUsername;Pwd=;

So something like: 所以类似于:

conn = new System.Data.Odbc.OdbcConnection();
conn.ConnectionString = @"FILEDSN=C:\path\to\dsn\file\here.dsn;Uid=myUsername;Pwd=;";

From here . 这里开始

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM