简体   繁体   English

未找到数据源名称且未指定默认驱动程序

[英]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. 只是总结一下我解决方案的所有部分。

  1. Uninstall any 32-bit Office apps (required for step 2) 卸载任何32位Office应用程序(步骤2所需)
  2. Install the Access 64-bit drivers 安装Access 64位驱动程序
  3. Re-install any 32-bit Office apps 重新安装任何32位Office应用程序
  4. 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: 注意:

  1. The driver name has been changed to Microsoft Access Text Driver 驱动程序名称已更改为Microsoft Access Text Driver
  2. The delimiter for the file extensions has been changed from a semi-colon to a comma . 文件扩展名的分隔符已从分号更改为逗号

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.

相关问题 未找到数据源名称且未指定默认驱动程序 - Data source name not found and no default driver specified “未找到数据源名称且未指定默认驱动程序”用于创建访问连接 - “Data source name not found and no default driver specified” for creating access connection ADODB连接-错误:找不到数据源名称,并且未指定默认驱动程序 - ADODB Connection - Error: Data source name not found and no default driver specified “未找到数据源名称且未指定默认驱动程序”错误 - “Data source name not found and no default driver specified” error ODBC错误-找不到数据源名称,并且未指定默认驱动程序 - ODBC Error - Data source name not found and no default driver specified 我的SQL连接错误Microsoft] [ODBC驱动程序管理器]找不到数据源名称,并且未指定默认驱动程序 - My Sql Connection error Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified 错误找不到数据源名称,并且在ADO.NET中没有使用Odbc指定默认驱动程序 - Error Data source name not found and no default driver specified with Odbc in ADO.NET 如何摆脱错误:“.net中找不到数据源名称,没有指定默认驱动程序”? - How to get rid of the error: “Data source name not found and no default driver specified” in .net? C# - 未找到数据源名称且未指定默认驱动程序异常错误 - C# - Data source name not found and no default driver specified Exception Error C#到AS400 / JD Edwards-运行程序-找不到数据源名称并且未指定默认驱动程序 - c# to AS400 / JD Edwards - run program - Data source name not found and no default driver specified
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM