C# OLEDBConnection.Open() 生成“未指定错误”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/96150/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
OLEDBConnection.Open() generates 'Unspecified error'
提问by Mike Smith
I have an application that uploads an Excel .xls file to the file system, opens the file with an oledbconnection object using the .open() method on the object instance and then stores the data in a database. The upload and writing of the file to the file system works fine but I get an error when trying to open the file on our production server only. The application works fine on two other servers (development and testing servers).
我有一个应用程序将 Excel .xls 文件上传到文件系统,使用对象实例上的 .open() 方法使用 oledbconnection 对象打开文件,然后将数据存储在数据库中。将文件上传和写入文件系统工作正常,但仅在我们的生产服务器上尝试打开文件时出现错误。该应用程序在另外两台服务器(开发和测试服务器)上运行良好。
The following code generates an 'Unspecified Error' in the Exception.Message.
以下代码在 Exception.Message 中生成“未指定错误”。
Quote:
引用:
System.Data.OleDb.OleDbConnection x = new System.Data.OleDb.OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + location + ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1'");
try
{
x.Open();
}
catch (Exception exp)
{
string errorEmailBody = " OpenExcelSpreadSheet() in Utilities.cs. " + exp.Message;
Utilities.SendErrorEmail(errorEmailBody);
}
:End Quote
:结束报价
The server's c:\\temp and c:\Documents and Settings\\aspnet\local settings\temp folder both give \aspnet full control.
服务器的 c:\\temp 和 c:\Documents and Settings\\aspnet\local settings\temp 文件夹都赋予 \aspnet 完全控制权。
I believe that there is some kind of permissions issue but can't seem to find any difference between the permissions on the noted folders and the folder/directory where the Excel file is uploaded. The same location is used to save the file and open it and the methods do work on my workstation and two web servers. Windows 2000 SP4 servers.
我相信存在某种权限问题,但似乎无法在指定文件夹的权限与上传 Excel 文件的文件夹/目录之间找到任何区别。相同的位置用于保存文件并打开它,这些方法在我的工作站和两个 Web 服务器上都有效。Windows 2000 SP4 服务器。
回答by Darren Kopp
Anything in the inner exception? Is this a 64-bit application? The OLEDB providers don't work in 64-bit. You have to have your application target x86. Found this when getting an error trying to open access DB on my 64-bit computer.
内部异常中有什么吗?这是 64 位应用程序吗?OLEDB 提供程序不适用于 64 位。您的应用程序必须面向 x86。在我的 64 位计算机上尝试打开访问数据库时遇到错误时发现了这一点。
回答by Danimal
I've gotten that error over the permissions thing, but it looks like you have that covered. I also have seen it with one of the flags in the connection string -- you might play with that a bit.
我在权限问题上遇到了那个错误,但看起来你已经涵盖了。我还看到它带有连接字符串中的一个标志——你可能会玩一下。
回答by Mike Smith
Yup. I did that too. Took out IMEX=1, took out Extended Properties, etc. I managed to break it on the dev and test servers. :) I put those back in one at a time until it was fixed on dev and test again but still no workie on prod.
是的。我也是这样做的。去掉 IMEX=1,去掉扩展属性等。我设法在开发和测试服务器上打破它。:) 我一次把它们放回原处,直到它在开发上得到修复并再次测试,但在生产上仍然没有工作人员。
回答by Joshua Turner
Try wrapping the location in single quotes
尝试将位置用单引号括起来
System.Data.OleDb.OleDbConnection x = new System.Data.OleDb.OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" + location + "';Extended Properties='Excel 8.0;HDR=Yes;IMEX=1'");
回答by domoaringatoo
While the permissions issue may be more common you can also encounter this error from Windows file system/Access Jet DB Engine connection limits, 64/255 I think. If you bust the 255 Access read/write concurrent connections or the 64(?) connection limit per process you can get this exact same error. At least I've come across that in an application where connections were being continually created and never properly closed. A simple Conn.close();
dropped in and life was good. I imagine Excel could have similar issues.
虽然权限问题可能更常见,但您也可以从 Windows 文件系统/Access Jet DB Engine 连接限制中遇到此错误,我认为是 64/255。如果您破坏了每个进程 255 个访问读/写并发连接或 64(?) 个连接限制,您会得到完全相同的错误。至少我在一个不断创建连接但从未正确关闭的应用程序中遇到过这种情况。一个简单的Conn.close();
下降和生活是美好的。我想 Excel 可能有类似的问题。
回答by StronglyTyped
If you're using impersonation you'll need to give permission to the impersonation user instead of/in addition to the aspnet user.
如果您使用模拟,则需要向模拟用户授予权限,而不是/除了 aspnet 用户之外。
回答by GideonMax
not sure if this is the problem you are facing,
but, before disposing of the connection, you should do Connection.Close(),
because the Connection.Dispose() command is inherited from Component and does not properly dispose of certain connection resources.
not properly disposing of the connection could lead to access issues.
不确定这是否是您面临的问题,
但是,在处理连接之前,您应该执行 Connection.Close(),
因为 Connection.Dispose() 命令是从 Component 继承的,并没有正确处理某些连接资源。
不正确处理连接可能会导致访问问题。