C#/ ASP.NET Oledb - MS Excel读取“未指定的错误” [英] C#/ASP.NET Oledb - MS Excel read "Unspecified error"

查看:175
本文介绍了C#/ ASP.NET Oledb - MS Excel读取“未指定的错误”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个在Windows Server 2003企业版上的IIS 6上运行的C#/ ASP.NET(2.0)应用程序。此应用程序使用OleDb读取Excel文件,但是当我们收到应用程序中抛出的未指定的错误异常时,会出现这种情况。



在打开之前,该文件由我们的文件上传代码存储在临时目录中。由于我们在IIS中启用了匿名访问,并且由于我们还在web.config中使用模拟,C:\Windows\Temp\文件夹具有Internet访客用户帐户(IUSR_ [MachineName])的正确权限,能够在那里创建,修改和删除文件。



OleDb连接字符串:

Provider = Microsoft.Jet.OLEDB.4.0; Data Source = C:\ Windows \Temp\tmp123.tmp.xls;

扩展属性=Excel 8.0; HDR =是; IMEX = 1;



[上面的数据源属性将针对每个文件进行更改。]

 
异常的堆栈跟踪是:
System.Exception:FileParsingFailed ---> System.Data.OleDb.OleDbException:

上未指定的错误System.Data.OleDb.OleDbConnectionInternal。
System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options,
Object poolGroupProviderInfo,DbConnectionPool pool,DbConnection owningObject)
系统(OleDbConnectionString,
OleDbConnection连接)在
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection
owningConnection)在
System.Data中的.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection
owningConnection,DbConnectionPoolGroup poolGroup)。 ProviderBase.DbConnectionClosed.OpenConnection(DbConnection
outerConnection,DbConnectionFactory conn ectionFactory)
System.Data.OleDb.OleDbConnection.Open()

解决方法: / b>

到目前为止,我们可以想出的唯一的解决办法是做一个iisreset(我们也将应用程序池回收配置为每天在IIS中发生一次,但似乎并没有帮助,这个问题有时会连续几天持续下去)。虽然这不是一件好事情,但更糟糕的是,我们在同一个网站上有其他应用程序,每当我们重置IIS时都会受到影响。



问题:

1.我们如何解决这个错误,因为它偶尔发生,我们看不到一种模式?

2.除了OleDb,还有什么比C#/ ASP.NET更好的(和免费的)处理Excel文件的方式吗? (我们不希望在Microsoft不推荐安装MS Office)



我们的限制:

1.我们坚持使用MS Office 2003(.xls)格式,无法移动到MS Office 2007(OOXML)格式。

2.我们不使用CSV的原因是因为我们可能在我们的数据中有逗号(即使我们使用引用也是很难处理的),我们还在我们的电子表格中使用了多个工作表(这不能用CSV完成)。



谢谢! :)



更新:

谢谢Keith。它似乎是Jet引擎的一个问题,但是由于缺少(免费和易于使用)的替代方案,我们使用它。

谢谢Joe。但是我们的预算有限,所以我们主要寻找免费的工具/库。

解决方案

我一直在使用SpreadSheetGear.NET一段时间,主要是创建Excel文件,它的工作正常。 p>

http://www.spreadsheetgear .com / products / spreadsheetgear.net.aspx



它在本机.NET中提供二进制Excel文件读取/写入,解决了我以前的所有问题遇到尝试使用OLE和JET来读取和创建Excel文件。



基本版本作为注册Visual C ++ Express 2005的perk而免费使用。这是无意的,所以2008年版可能还可能不存在。


We have a C#/ASP.NET (2.0) application running on IIS 6 on Windows Server 2003 Enterprise Edition. This application reads Excel files using OleDb, but there are instances when we get an "Unspecified Error" exception thrown from within the application.

The file is stored in the temporary directory by our file upload code before opening. Since we have anonymous access enabled in IIS and since we also use impersonation in web.config, the folder C:\Windows\Temp\ has the proper permissions for the Internet Guest User Account (IUSR_[MachineName]) to be able to create, modify and delete files there.

OleDb connection string:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Windows\Temp\tmp123.tmp.xls;
Extended Properties="Excel 8.0;HDR=Yes;IMEX=1;"

[The "Data Source" attribute above would change for every file.]

The stack trace of the exception is:
    System.Exception: FileParsingFailed ---> System.Data.OleDb.OleDbException:  
    Unspecified error 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()  

Workaround:
So far, the only workaround we could come up with was to do an iisreset (we also have application pool recycling configured to happen once everyday in IIS, but it doesn't seem to help since the issue sometimes persists over several consecutive days). While this is not a good thing to do, what makes it worse is that we have other applications on the same web site that would get impacted whenever we reset IIS.

The questions:
1. How do we resolve this error since it happens occasionally and we don't see a pattern?
2. Are there any better (and free) ways of processing Excel files from C#/ASP.NET apart from OleDb? (We prefer not to install MS Office on the servers since it's not recommended by Microsoft)

Our limitations:
1. We're stuck with the MS Office 2003 (.xls) format and cannot move to the MS Office 2007 (OOXML) format.
2. The reasons we don't use CSV are because we may have commas within our data (this is a pain to deal with even if we use quoting) and we also use multiple worksheets in our spreadsheet (this cannot be done with CSV).

Thanks! :)

Update:
Thanks, Keith. It does seem like an issue with the Jet engine, but we use it because of the lack of (free and easy to use) alternatives.
Thanks, Joe. But we're on a limited budget - so we're mainly looking for free tools/libraries.

解决方案

I've been using SpreadSheetGear.NET for a while, mostly to create Excel files, and it works well.

http://www.spreadsheetgear.com/products/spreadsheetgear.net.aspx

It provides binary Excel file reading/writing in native .NET, solving all the previous problems I've encountered trying to use OLE and JET to read and create Excel files.

The basic version used to come free as a perk for registering Visual C++ Express 2005. This was unadvertised, so it may or may not still exist with the 2008 edition.

这篇关于C#/ ASP.NET Oledb - MS Excel读取“未指定的错误”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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