错误与C#打开Excel文件 [英] Error with opening an Excel file from C#

查看:169
本文介绍了错误与C#打开Excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图打开一个excel文件的连接时收到以下错误:

I'm getting the following error when attempting to open a connection to an excel file:

The Microsoft Access database engine cannot open or write to the file ''. It is already             opened exclusively by another user, or you need permission to view and write its data.

at System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr,            
OleDbConnection connection) at     
System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options,   
Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject) at 
System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection 
owningConnection, DbConnectionPoolGroup poolGroup) at 
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection 
owningConnection) at 
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection 
outerConnection, DbConnectionFactory connectionFactory) at 
System.Data.OleDb.OleDbConnection.Open() 

当我部署到服务器只会出现此问题。我试过在两个不同的服务器:
32比特及64位。这两种运行Windows Server 2008 SP 2,code ++工程,我的本地机器(Windows 7)中的罚款。我已经安装了Microsoft Office 2007的两台服务器以及希望的一个必要的dll会解决这个问题的。我使用Excel文件中的连接字符串如下:

This problem only occurs when I deploy to a server. I've tried on two different servers: 32 bit & 64 bit. Both running Windows Server 2008 SP 2. The code works fine on my local machine (Windows 7). I've installed Microsoft office 2007 on both servers as well hoping that a necessary dll would have resolved the issue. The connection string I'm using for the excel file is as follows:

string result = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + _fileName + ";Extended Properties=\"Excel 12.0;HDR=NO;\"";

该_filename变量是该文件的位置的绝对路径。我已经通过直接在网站的目录放置一个文件,试图调试和所有用户的权限设置为完全控制,但仍然无法正常工作。

The _fileName variable is an absolute path to the file's location. I've tried debugging by placing a file directly in the website's directory and set the permissions to full control for all users, but still doesn't work.

我需要从我的web应用程序查询的Excel文件的内容,并将其展示给用户。该Excel文件可以有不同的布局中输入数据的方式。

I need to query the contents of excel files from my web application and display them to the user. The excel files can have different layouts in the way the data is entered.

有什么我失踪,我需要为了得到这个服务器上的工作怎么办?

Is there anything I'm missing which I need to do in order to get this to work on the server?

推荐答案

请通过下面的链接,这是非常有帮助的,我解决我的下吧。

Please go through below link which is very helpful, I solved mine following it.

<一个href=\"http://answers.microsoft.com/en-us/windows/forum/windows_7-windows_programs/windows-7-and-i-have-a-batch-file-to-copy-files/311cdd34-40a2-417c-bb7d-ca96a7ef56ee\" rel=\"nofollow\">http://answers.microsoft.com/en-us/windows/forum/windows_7-windows_programs/windows-7-and-i-have-a-batch-file-to-copy-files/311cdd34-40a2-417c-bb7d-ca96a7ef56ee

这篇关于错误与C#打开Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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