的ConnectionString获取一个Excel文件的问题 [英] ConnectionString For Getting An Excel File Problem

查看:362
本文介绍了的ConnectionString获取一个Excel文件的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

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

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 =我的项目名称

aaa = My Project Name

与此连接字符串的每一件事情是在当地还算可以,但上传后的网站我有一个错误。

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

问题出在哪里?

这是真正的路径 - >〜/ ExcelFiles / a.xlsx与否

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

U可以修复这条道路4我....

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?

由于在今后的前进

问候

推荐答案

你主持的文件上没有ACE OLEDB用于安装Office驱动程序的机器。我会切换到JetOleDB司机

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

一个喷气OLEDB连接字符串看起来像

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是2003版的,我相信。 2007年,你会想用Excel12.0

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

所以,我会这样是做的String.Format和简单地传递过程中的Excel文件的位置,因为这似乎是一个asp.net应用程序就应该是这个样子:

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

当然你也可以简单地把在你的配置中的String.Format使用的字符串文件的方式也不是很难codeD像我有它。

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.

这篇关于的ConnectionString获取一个Excel文件的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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