JCS2009
asked on
ASP.NET System.Data.OleDb.OleDbException: Unspecified error reading Excel file
I have the following code in a web service that attempts to open an excel file for reading:
System.Data.OleDb.OleDbCon nection xcn = new System.Data.OleDb.OleDbCon nection();
xcn.ConnectionString = "Provider=Microsoft.Jet.OL EDB.4.0;Da ta Source=" + filePath + ";Extended Properties=\"Excel 8.0;IMEX=1\"";
xcn.Open();
In our production environment this starts to fail once or twice a day and the only way I can fix is with IISRESET /RESTART. Here is the error I get:
System.Data.OleDb.OleDbExc eption: Unspecified error
at System.Data.OleDb.OleDbCon nectionInt ernal..cto r(OleDbCon nectionStr ing constr, OleDbConnection connection)
at System.Data.OleDb.OleDbCon nectionFac tory.Creat eConnectio n...
I have checked permissions on various temp folders that JET supposedly uses, and permissions are fine. The most frustrating thing is that it will work for several times in a row, and then start failing every time (until IISREST).
Any thoughts?
System.Data.OleDb.OleDbCon
xcn.ConnectionString = "Provider=Microsoft.Jet.OL
xcn.Open();
In our production environment this starts to fail once or twice a day and the only way I can fix is with IISRESET /RESTART. Here is the error I get:
System.Data.OleDb.OleDbExc
at System.Data.OleDb.OleDbCon
at System.Data.OleDb.OleDbCon
I have checked permissions on various temp folders that JET supposedly uses, and permissions are fine. The most frustrating thing is that it will work for several times in a row, and then start failing every time (until IISREST).
Any thoughts?
ASKER
Yes, I am calling xcn.Close() at the end of the code that reads from the Excel file.
Try turning off connection pooling by adding ' pooling = false' to your connection string. So it will now be:
System.Data.OleDb.OleDbCon nection xcn = new System.Data.OleDb.OleDbCon nection();
xcn.ConnectionString = "Provider=Microsoft.Jet.OL EDB.4.0;Da ta Source=" + filePath + ";Extended Properties=\"Excel 8.0;IMEX=1\";pooling=false ;";
xcn.Open();
xcn.ConnectionString = "Provider=Microsoft.Jet.OL
xcn.Open();
ASKER
I will try this in production as soon as I can and report back. I can't find documentation on that extended property. Can you point me to some? Thanks for the suggestion.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I am going through this problem..
does setting "pooling=false" fixed the issue?
does setting "pooling=false" fixed the issue?
I'm not sure how ODBC and Excel work with connection pooling, but if you open the Excel file multiple times, eventually you will run out of file handles and the connection will fail. The .Net garbage collector will close the connections, but it will happen randomly and you will have no control on when that will happen.