C#/ ASP.NET OLEDB - MS Excel中读取和QUOT;未指定的错误" [英] C#/ASP.NET Oledb - MS Excel read "Unspecified error"

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

问题描述

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

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.

该文件打开之前存储在临时目录中我们的文件上传code。既然我们已经在IIS中启用匿名访问因为我们还使用模拟在web.config中,该文件夹C:\\ WINDOWS \\ TEMP \\对Internet来宾用户帐户适当的权限(IUSR_ [计算机名])能够创建,修改并有删除文件。

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连接字符串:

供应商= Microsoft.Jet.OLEDB.4.0;数据源= C:\\ WINDOWS \\ TEMP \\ tmp123.tmp.xls;

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

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

解决方法:

至此,我们可以想出了做一个IISRESET唯一的解决方法(我们也有配置在IIS每天发生一次应用程序池回收,但它似乎并没有帮助,因为这个问题有时持续连续几天)。虽然这不是做一件好事,是什么使情况变得更糟的是,我们在同一个网站上,每当我们重置IIS将获得影响其他应用程序。

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.

的问题:

1.因为偶尔发生,我们没有看到一个模式,我们如何解决这个问题?

2.是否有从C#/ ASP.NET除了OleDb的处理Excel文件中的任何更好的(而且免费)的方式? (我们preFER不要在服务器上安装MS Office,因为它不建议由Microsoft)

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)

我们的限制:

1.我们坚持与微软Office 2003(.xls)格式,并不能移动到MS Office 2007的(OOXML)格式。

2.原因,我们不使用CSV是因为我们可能有我们的数据中的逗号(这是对付即使我们使用引用了痛苦),我们在我方第preadsheet也使用多个工作表(这不可能是与CSV完成)。

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

谢谢! :)

更新:

谢谢,基思。它似乎像Jet引擎的一个问题,但我们使用它因为缺乏(免费的和易于使用)的替代品。

谢谢你,乔。但我们在有限的预算 - 所以我们主要寻找免费工具/库。

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.

推荐答案

我一直在使用S preadSheetGear.NET一段时间,主要是为了创建Excel文件,并且效果很好。

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

HTTP://www.s$p$ padsheetgear.com/products/s$p$padsheetgear.net.aspx

它提供了二进制的Excel文件的读/原生.NET编写,解决我遇到了试图使用OLE和JET读取和创建Excel文件的所有previous问题。

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.

常来免费为振作登记的Visual C ++防爆preSS 2005年这是未公开的,因此它可能会或可能不会仍然与2008年版中存在的基本版本。

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中读取和QUOT;未指定的错误"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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