ConnectionString For Getting An Excel File Problem

偶尔善良 提交于 2019-11-28 12:06:12

问题


in have an Excel File Named (a.xlsx) in A Folder Named (ExcelFiles).

the ExcelFiles Folder Is located in the root Of my project.

so my connection string for getting excel file data is like this :

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

aaa = My Project Name

with this connection string every thing is ok in local , but after upload web site i have an error.

where is the problem??

is this path true -> ~/ExcelFiles/a.xlsx or not

can u fix this path 4 me....

after solving the path problem the error is like this :

 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.

how can i do with this error?

thanks in future advance

best regards


回答1:


The machine you're hosting the file on doesn't have the ACE OleDB for office driver installed. I would switch to the JetOleDB driver

A Jet OleDB connection string looks like

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

Excel8.0 is version 2003 I believe. For 2007 you will want to use Excel12.0

So what I would so is to do a String.Format and simply pass in the location of the excel file, of course since this appears to be an asp.net application it should look something like this:

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) );

You can of course simply put the String used in the String.Format in your config file that way it isn't hard coded like I have it.




回答2:


Have a look at the following url, it has information on how to resolve this problem

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



来源:https://stackoverflow.com/questions/3971723/connectionstring-for-getting-an-excel-file-problem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!