none
No error message available, result code: E_FAIL(0x80004005).

    Question

  • hi friends

        i try to connect to ms excel in asp.net 2.0

     

    protected void Button1_Click(object sender, EventArgs e)

    {

     DataTable worksheets; string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=Spain_test.xls;Extended Properties=""Excel 8.0;HDR=YES;""";

    using (System.Data.OleDb.OleDbConnection connection = new System.Data.OleDb.OleDbConnection(connectionString))

     {

    connection.Open();

    worksheets = connection.GetSchema("Tables");

    }

    }

    but i got

     

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Data.OleDb.OleDbException: No error message available, result code: E_FAIL(0x80004005).

    Source Error: Line 23: using (System.Data.OleDb.OleDbConnection connection = new System.Data.OleDb.OleDbConnection(connectionString))

     Line 24:

    {

     Line 25: connection.Open();

     Line 26: worksheets = connection.GetSchema("Tables");

     Line 27: } Source File: d:\televident\filuload.aspx.cs

     Line: 25 Stack Trace: [OleDbException (0x80004005):

    No error message available, result code: E_FAIL(0x80004005).] System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection) +1054769 System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject) +53 System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup) +27 System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +47 System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +105 System.Data.OleDb.OleDbConnection.Open() +37 filuload.Button1_Click(Object sender, EventArgs e) in d:\televident\filuload.aspx.cs:25 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102

    plz help me

    Monday, June 26, 2006 7:36 AM

Answers

  • Make sure that the xl file exists in the bin folder. Otherwise, try giving absolute path of the xl file in the connection string.

     

    Monday, June 26, 2006 10:04 AM

All replies

  • Make sure that the xl file exists in the bin folder. Otherwise, try giving absolute path of the xl file in the connection string.

     

    Monday, June 26, 2006 10:04 AM
  • thanks badri, i did not try full path previously

     btw their is no bin folder

     which were of you talking?

    Monday, June 26, 2006 11:11 AM
  • Hello I know this is an older post but I had the same problem. My problem was I had the document open on another computer which obviously locked the file for exclusive access.
    Thursday, October 19, 2006 1:10 PM
  • I'm having this error now and it isn't making any sense. A little back information:

    _memberLoadFile is a FileInfo object and the object is there and resides in the App_Data folder.

     

    I can connect to the Excel file just fine and the following works,


     

    Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _memberLoadFile.FullName & ";Extended Properties=""Excel 8.0;HDR=YES;"""

    Dim dt As New DataTable()

    Using connection As New OleDbConnection(connectionString)

    Dim commandText As String = _

    "SELECT " & _

    " [MemberID] AS [ID] " & _

    "FROM [Members$]"

     

    Dim command As New OleDbCommand(commandText, connection)

    connection.Open()

    Using dr As OleDbDataReader = command.ExecuteReader()

    ....[snip].....

     


    However the following doesn't work and all i did was add CAST around MemberID. I have even taken off the "AS [ID]" and it still doesn't work. If i go back to the previous working example it works.


     

    Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _memberLoadFile.FullName & ";Extended Properties=""Excel 8.0;HDR=YES;"""

    Dim dt As New DataTable()

    Using connection As New OleDbConnection(connectionString)

    Dim commandText As String = _

    "SELECT " & _

    " CAST([MemberID] AS VARCHAR(255)) AS [ID] " & _

    "FROM [Members$]"

     

    Dim command As New OleDbCommand(commandText, connection)

    connection.Open()

    Using dr As OleDbDataReader = command.ExecuteReader()

    ....[snip].....

    Tuesday, March 27, 2007 3:02 PM
  • Having the same problem, did you ever find a solution?

    • Proposed as answer by Cedar Rapids Friday, January 29, 2010 3:14 PM
    Wednesday, November 28, 2007 12:22 PM
  • Try opening the excel document and saving as Excel 97 workbook.
    Wednesday, January 02, 2008 9:24 PM
  • hi,
    probably you were not giving the full permissin to ure excel file. give the full permission by creating an aspnet account to the containing folder or file.it will work.
    Thursday, June 05, 2008 12:35 PM
  • Here's some food for thought. If you have "-" anywhere in your file path and you reference the file path in the command to pull the item in, the OLEDB Command will tell you that you have invalid characters in your path. That is, you will only get this message once you wrap your FROM object with [].  For example, "SELECT * FROM C:\the-path\file.csv" will give you the error referenced above. If you pass the command this instead "SELECT * FROM [C:\the-path\file.csv]", it will tell you that it is not a valid name.

    'C:\the-path\file.csv' is not a valid name. Make sure that it does not include invalid characters or punctuation and that it is not too long.

    Background: I was just having this problem after things were working before. We recently moved to subversion and had to rename our repositories. I was having this issue and came across this forum. However, I found giving permissions all the way didn't solve anything.  So I started to look at all of the other variables that were different between the project as it was before and the way it is now and saw the "-" in the file path.  On a hunch I renamed the file path, and re ran the tests.  It worked perfectly.

    Then I looked into the actual command instead of the data source. The connection string turned out to be fine with the "-", but the command itself considered it an invalid character.  Taking the path out of the command fixed the problem.  But what happens if I use "-" in the file name? 

     

    Question: What is the escape character for OLEDB Commands in reference to the Jet Engine (or in general)?


    Robz
    Friday, January 23, 2009 2:57 PM
  • Having the same problem, did you ever find a solution?

    I found that when uploading a file that was 32000 rows failed, but when uploading only 12000 row it worked.  Still have found a fix though.
    Friday, January 29, 2010 3:16 PM
  • Use square brackets to force the dash to be recognized as apart of the string.

    string file = "C:\file-abc.csv"

    string query = "SELECT * FROM [" + file + "]";

    Friday, March 16, 2012 4:32 PM