找不到数据源名称,并且未指定默认驱动程序 [英] Data source name not found and no default driver specified

查看:707
本文介绍了找不到数据源名称,并且未指定默认驱动程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被要求将一个使用MVP模式的WinForms应用程序移植到一个网页。该应用程序(除其他外)将CSV文件上传到DataTable,然后进行一些工作。



CSV文件已上传到服务器,然后阅读以下

  string connectionString = @Driver = {Microsoft Text Driver(* .txt; * .csv)}; Extensions = asc ,csv,tab,txt; Persist Security Info = False; Dbq = C:\Temp\; 

//检查该文件是否存在并且格式正确
if(File.Exists(this.WorkingFileName))
{
using(OdbcConnection connection = new OdbcConnection连接字符串))
{
//确定行数
string selectCount =select count(*)from [MyFile.csv]);

using(OdbcCommand command = new OdbcCommand(selectCount,connection))
{
connection.Open();
}
}
}

错误:


错误[IM002] [Microsoft] [ODBC驱动程序
Manager]找不到数据源名称
没有默认驱动程序指定


现在代码在WinForms中正常工作,但在网络上失败。有什么我需要更改在IIS,我的配置文件或其他东西,让这段代码工作吗?



OK

所以我弄清楚了我的两个代码版本之间有什么不同:WinForms版本是作为32位运行,一旦我把它改为64位,它提出了同样的错误。请参阅:
32位文本驱动程序(Microsoft Access,Microsoft Excel和文本文件)从Windows 7上的64位应用程序



要修复我安装的从 http://www.microsoft.com/download/访问64位驱动程序en / details.aspx?displaylang = en& id = 13255 但我仍然得到相同的错误。



如果我检查我的ODBC数据源管理员,请参阅Microsoft Access文本驱动程序(* .txt,* .csv)| 14.00.47600.1000 | Microsoft Corporation | ACEODBC.dll



,所以为什么还是会失败?

解决方案

好的,我发现了问题。


  1. 卸载任何32位Office应用程序(步骤2需要)

  2. a href =http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=13255 =nofollow noreferrer>访问64位驱动程序

  3. 重新安装任何32位Office应用程式


  4. 两个位置中的连接字符串更改为看到这里到:



    @Driver = {Microsoft Access Text Driver(* .txt,* .csv)}; Extensions = asc, csv,tab,txt; Persist Security Info = False; Dbq = C:\ Temp \



  1. 驱动程序名称已更改为
    Microsoft 访问文本驱动程序

  2. 文件扩展名
    的分隔符已从分号
    更改为逗号



    1. 我没有发现引起我很多痛苦的逗号变化: - (


      I have been asked to port a WinForms app that uses the MVP pattern over to a webpage. The app, amongst other things, uploads a CSV file to a DataTable and then does some work.

      The CSV file is uploaded to the server OK and then read with the following code

      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

      Now the code works fine in WinForms but fails on the web. Is there something I need to change in IIS, my config file or something else to get this code to work? 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. See: 32-bit Text drivers (Microsoft Access , Microsoft Excel and Text files ) from a 64 bit application on windows 7

      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.

      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

      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)
      2. Install the Access 64-bit drivers
      3. Re-install any 32-bit Office apps
      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\"

      Note that:

      1. The driver name has been changed to 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 :-(

      这篇关于找不到数据源名称,并且未指定默认驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆