在VS2012中运行代码时访问Excel文件时出现问题 [英] Problem accessing Excel files when running code in VS2012
问题描述
我知道这是一个常见的问题但是这里有。
I know this is a common problem but here goes.
我有一个Dot Net C#网络应用程序,已经生产了几年,现在没有任何问题。 我有一段时间没有看过它。 其中一项功能是能够上传Excel(xls,而不是xlsx)文件并阅读它们。
I have a Dot Net C# web app that has been in production for a couple of years now without any problem. I haven't looked at it for a while. One of the features is the ability to upload Excel (xls, not xlsx) files and read them.
当我尝试在VS2012中运行它时,它突然崩溃了。
"Microsoft.ACE.OLEDB.12.0"提供程序未在本地计算机上注册。
All of a sudden it's crashing on me when I try to run it in VS2012. The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.
(我怀疑是因为我必须支持多个项目,因此无法确定其他功能可能与此应用程序存在冲突。 我最近才安装了Office 2013.)
(I suspect it is because I have to support multiple projects, so there's no telling what other feature may have a conflict with this app. Also I only recently had Office 2013 installed.)
使用的代码如下:
The code used is as follows:
s = " Provider = Microsoft.ACE.OLEDB.12.0; Data Source = C:\\inetpub \\wwwroot \\Apps \\Src \\\\\\\ MyAppName5 \\\ \\ MyApp\\Files \\FileName.xls;扩展属性= Excel 12.0 Xml"
s= "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\inetpub\\wwwroot\\Apps\\Src\\Web\\MyAppName5\\MyApp\\Files\\FileName.xls;Extended Properties=Excel 12.0 Xml"
DataSet ds = new DataSet();
DataSet ds = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter(" SELECT * FROM [ PageName $]",s);
OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM [PageName$]", s);
da.Fill(ds);
da.Fill(ds);
此时它崩溃了。
At this point it crashes.
我在Windows 7 64位计算机上本地运行。 我安装了64位驱动程序: Microsoft Access数据库引擎2010,版本14.0.7015.1000。   
I'm running this locally on a Windows 7 64 bit machine. I have the 64 bit driver installed: Microsoft Access database engine 2010, Version 14.0.7015.1000.
另一方面,我可能还安装了另一个驱动程序: Microsoft.ACE.OLEDB.15.0  
On the other hand I may have yet another driver installed as well: Microsoft.ACE.OLEDB.15.0
我从我在线找到的Powershell查询中得到了这个: (New-Object system.data.oledb.oledbenumerator ).GetElements()|选择SOURCES_NAME,SOURCES_DESCRIPTION
我在控制面板/程序和功能中没有看到任何内容来确认这一点。
I got this from a Powershell query I found on line: (New-Object system.data.oledb.oledbenumerator).GetElements() | select SOURCES_NAME, SOURCES_DESCRIPTION
I don't see anything in the Control Panel/Programs and Features to confirm this.
(我不是Powershell专家。)
(I am not a Powershell expert.)
建议?
推荐答案
我不知道您的应用程序是配置为运行32位还是运行64位。您是否尝试将项目平台更改为x86(32位)?
I don't know whether your app is configured to run 32-bit or is running 64-bit. Have you tried changing the Platform of the project to x86 (32-bit)?
这篇关于在VS2012中运行代码时访问Excel文件时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!