简体   繁体   English

OLEDBConnection.Open() 生成“未指定错误”

[英]OLEDBConnection.Open() generates 'Unspecified error'

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.我有一个应用程序将 Excel .xls 文件上传到文件系统,使用对象实例上的 .open() 方法使用 oledbconnection 对象打开文件,然后将数据存储在数据库中。 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).该应用程序在另外两台服务器(开发和测试服务器)上运行良好。

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.我相信存在某种权限问题,但似乎无法在指定文件夹的权限与上传 Excel 文件的文件夹/目录之间找到任何区别。 The same location is used to save the file and open it and the methods do work on my workstation and two web servers.相同的位置用于保存文件并打开它,这些方法在我的工作站和两个 Web 服务器上都有效。 Windows 2000 SP4 servers. Windows 2000 SP4 服务器。

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.虽然权限问题可能更常见,但您也可以从 Windows 文件系统/Access Jet DB Engine 连接限制中遇到此错误,我认为是 64/255。 If you bust the 255 Access read/write concurrent connections or the 64(?) connection limit per process you can get this exact same error.如果您破坏了每个进程 255 个访问读/写并发连接或 64(?) 个连接限制,您会得到完全相同的错误。 At least I've come across that in an application where connections were being continually created and never properly closed.至少我在一个不断创建连接但从未正确关闭的应用程序中遇到过这种情况。 A simple Conn.close();一个简单的Conn.close(); dropped in and life was good.进去了,生活很好。 I imagine Excel could have similar issues.我想 Excel 可能有类似的问题。

如果您使用模拟,则需要向模拟用户授予权限,而不是/除了 aspnet 用户之外。

尝试将位置用单引号括起来

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'");

not sure if this is the problem you are facing,不确定这是否是您面临的问题,
but, before disposing of the connection, you should do Connection.Close(),但是,在处理连接之前,您应该执行 Connection.Close(),
because the Connection.Dispose() command is inherited from Component and does not properly dispose of certain connection resources.因为 Connection.Dispose() 命令是从 Component 继承的,并没有正确处理某些连接资源。
not properly disposing of the connection could lead to access issues.不正确处理连接可能会导致访问问题。

Anything in the inner exception?内部异常中有什么吗? Is this a 64-bit application?这是 64 位应用程序吗? The OLEDB providers don't work in 64-bit. OLEDB 提供程序不适用于 64 位。 You have to have your application target x86.您的应用程序必须面向 x86。 Found this when getting an error trying to open access DB on my 64-bit computer.在我的 64 位计算机上尝试打开访问数据库时遇到错误时发现了这一点。

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.我还看到它带有连接字符串中的一个标志——你可能会玩一下。

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.去掉 IMEX=1,去掉扩展属性等。我设法在开发和测试服务器上打破它。 :) I put those back in one at a time until it was fixed on dev and test again but still no workie on prod. :) 我一次把它们放回原处,直到它在开发上得到修复并再次测试,但在生产上仍然没有工作人员。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM