Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 获取Excel文件问题的ConnectionString_C#_Asp.net_Excel_Connection String - Fatal编程技术网

C# 获取Excel文件问题的ConnectionString

C# 获取Excel文件问题的ConnectionString,c#,asp.net,excel,connection-string,C#,Asp.net,Excel,Connection String,在中,在名为(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"/> The 'Mic

在中,在名为(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"/>
 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.
如何处理此错误

提前谢谢你


致以最诚挚的问候

请查看以下url,它提供了有关如何解决此问题的信息


承载文件的计算机未安装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中使用的字符串放在您的配置文件中,这样它就不会像我这样硬编码。

谢谢您的回答/但该错误会从服务器和本地触发,一切正常/您建议的程序安装在本地//我如何在该服务器中使用它?您需要在服务器中安装驱动程序为了让它发挥作用,或者看看@Justin关于迁移到JetTHANKS的建议/驱动程序问题已经解决/但是数据源中的绝对路径呢?(非常感谢您的回答)我已经修改了我的答案,以展示这些想法,因为它们比可以在这里发布的内容要长一点。