开发者

ConnectionString For Getting An Excel File Problem

开发者 https://www.devze.com 2023-01-21 13:56 出处:网络
in have an Excel File Named (a.xlsx)开发者_Go百科 in A Folder Named (ExcelFiles). the ExcelFiles Folder Is located in the root Of my project.

in have an Excel File Named (a.xlsx)开发者_Go百科 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


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消