[英]Data source name not found and no default driver specified
I have been asked to port a WinForms app that uses the MVP pattern over to a webpage. 我被要求将使用MVP模式的WinForms应用程序移植到网页上。 The app, amongst other things, uploads a CSV file to a DataTable and then does some work. 除其他外,该应用程序将CSV文件上传到DataTable,然后执行一些操作。
The CSV file is uploaded to the server OK and then read with the following code CSV文件上传到服务器确定,然后使用以下代码读取
string connectionString = @"Driver={Microsoft Text Driver (*.txt; *.csv)};Extensions=asc,csv,tab,txt;Persist Security Info=False;Dbq=C:\Temp\";
//check that file exists and in correct format
if (File.Exists(this.WorkingFileName))
{
using (OdbcConnection connection = new OdbcConnection(connectionString))
{
// Determine number of rows
string selectCount = "select count(*) from [MyFile.csv]");
using (OdbcCommand command = new OdbcCommand(selectCount, connection))
{
connection.Open();
}
}
}
at this point I get the error: 在这一点上我得到错误:
ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified 错误[IM002] [Microsoft] [ODBC驱动程序管理器]未找到数据源名称且未指定默认驱动程序
Now the code works fine in WinForms but fails on the web. 现在,代码在WinForms中运行良好,但在Web上失败。 Is there something I need to change in IIS, my config file or something else to get this code to work? 有什么我需要在IIS,我的配置文件或其他东西中更改以使此代码工作? Or is there something more fundamental I need to do? 还是我需要做一些更基本的事情?
Update 更新
OK so I worked out what was different between my two code versions: The WinForms version was running as 32-bit, as soon as I changed it to 64-bit it threw the same error. 好的,所以我找出了我的两个代码版本之间的不同之处:WinForms版本运行为32位,一旦我将其更改为64位,它就会抛出相同的错误。 See: 32-bit Text drivers (Microsoft Access , Microsoft Excel and Text files ) from a 64 bit application on windows 7 请参阅: Windows 7上的64位应用程序中的32位文本驱动程序(Microsoft Access,Microsoft Excel和文本文件)
To fix things I installed the Access 64-bit drivers from http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=13255 but I still get the same error. 为了解决问题,我从http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=13255安装了Access 64位驱动程序,但我仍然遇到同样的错误。
If I check my ODBC Data Source Administrator I can see "Microsoft Access Text Driver (*.txt, *.csv) | 14.00.47600.1000 | Microsoft Corporation | ACEODBC.dll 如果我检查我的ODBC数据源管理器,我可以看到“Microsoft Access文本驱动程序(* .txt,* .csv)| 14.00.47600.1000 | Microsoft Corporation | ACEODBC.dll
So it looks like they're installed OK, so why would it still be failing? 所以看起来它们安装好了,为什么它仍然会失败?
OK, I found the problem. 好的,我发现了问题。 Just to summarise all the parts to my solution. 只是总结一下我解决方案的所有部分。
Change the connection string in TWO places as can be seen here to: 更改连接字符串在两个地方可以看出这里来:
@"Driver={Microsoft Access Text Driver (*.txt, *.csv)};Extensions=asc,csv,tab,txt;Persist Security Info=False;Dbq=C:\\Temp\\" @“Driver = {Microsoft Access Text Driver(* .txt,* .csv)}; Extensions = asc,csv,tab,txt; Persist Security Info = False; Dbq = C:\\ Temp \\”
Note that: 注意:
I didn't spot the comma change which caused me a lot of pain :-( 我没有发现导致我很多痛苦的逗号变化:-(
This is probably due to the webserver not having the Jet Library installed, which I believe provides the Text Driver. 这可能是由于网络服务器没有安装Jet库,我相信它提供了文本驱动程序。 It is probably installed locally due to coming with MS Office (again, I believe this is the case) 它可能是由于MS Office的到来而在本地安装的(再次,我相信是这种情况)
Is the connection string well formed? 连接字符串是否形成良好? It seems that the dbq parameter is wrong. 似乎dbq参数是错误的。
"Driver={Microsoft Text Driver (*.txt; *.csv)};Extensions=asc,csv,tab,txt;Persist Security Info=False;Dbq=**C:Temp\\**"
Also take a look at this link , provides useful connection string samples 另外看一下这个链接 ,提供有用的连接字符串示例
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.