【问题标题】:ConnectionString For Getting An Excel File ProblemConnectionString 获取 Excel 文件问题
【发布时间】:2010-10-19 19:02:09
【问题描述】:

在名为 (ExcelFiles) 的文件夹中有一个名为 (a.xlsx) 的 Excel 文件。

ExcelFiles 文件夹位于我项目的根目录中。

所以我获取excel文件数据的连接字符串是这样的:

<add name="xlsx" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=aaa\ExcelFiles\a.xlsx;Extended Properties=Excel 12.0"/>

aaa = 我的项目名称

使用这个连接字符串在本地一切正常,但上传网站后出现错误。

问题出在哪里??

这条路径是否为真 -> ~/ExcelFiles/a.xlsx

你能修好这条路吗 4 me....

解决路径问题后报错如下:

 The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.

我该如何处理这个错误?

提前感谢

最好的问候

【问题讨论】:

    标签: c# asp.net excel connection-string


    【解决方案1】:

    您托管文件的计算机没有安装 ACE OleDB for office 驱动程序。我会切换到 JetOleDB 驱动程序

    Jet OleDB 连接字符串看起来像

    Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties="Excel 8.0;HDR=Yes;IMEX=1";
    

    我相信Excel8.0是2003版。对于 2007,您将需要使用 Excel12.0

    所以我要做的是做一个 String.Format 并简单地传递 excel 文件的位置,当然,因为这似乎是一个 asp.net 应用程序,它应该看起来像这样:

    String con = String.Format( @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties="Excel 8.0;HDR=Yes;IMEX=1"", Server.MapPath(EXCEL FILE LOCATION) );
    

    您当然可以简单地将 String.Format 中使用的字符串放在您的配置文件中,这样它就不会像我那样硬编码了。

    【讨论】:

    • 非常感谢/驱动程序问题已解决/但是关于数据源中的绝对路径呢? (非常感谢您的回答)
    • 我已经修改了我的答案以展示这些想法,因为它们比可以在此处发布的内容要长一些。
    【解决方案2】:

    看看下面的网址,里面有关于如何解决这个问题的信息

    http://www.microsoft.com/downloads/en/details.aspx?FamilyID=7554F536-8C28-4598-9B72-EF94E038C891&displaylang=en

    【讨论】:

    • 感谢您的回答/但该错误从服务器触发,并且在本地一切正常/您建议的程序安装在本地//我如何在该服务器中使用它?
    • 您需要在服务器中安装驱动程序才能使其工作或查看@Justin 的建议以迁移到 Jet
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-29
    • 1970-01-01
    • 2013-03-19
    • 1970-01-01
    相关资源
    最近更新 更多