none
System.Data.OleDb.OleDbException: Failure creating file

    Question

  • Hi,
    I am trying to Read an excel file using asp.net. It(Asp.net code) works fine, if I run it locally and the excel file is also local. But if I move the excel file to the web server it is giving an error.


    I gave aspnet account read &write permission.
    Here is my code and the error i get

    Dim FileName As String = txtFile.Value.ToString    'User will choose the file
    FileName = "\\sfddev-01\e$\wwwroot\ignet\dodworld\webapplications\test\test.xls"   'Hardcoded to test
    Dim strConn As String = "Provider=Microsoft.Jet.OleDb.4.0;" _
                                 & "data source= '" & FileName & "';" _
                                 & "Extended Properties=Excel 8.0;"
            Dim objConnOLE As New OleDbConnection(strConn)
            Dim strSql As String = "Select LastName, FirstName, Address, City, State,LastName From Addresses"
           
            strSql = "SELECT * FROM [Sheet1$]"
            Dim objCmd As New OleDbCommand(strSql, objConnOLE)
            Try
                objConnOLE.Open()   'Error occurs here. **** LINE 87 of error ****
            


    Error:
    System.Data.OleDb.OleDbException: Failure creating file. at System.Data.OleDb.OleDbConnection.ProcessResults(Int32 hr) at System.Data.OleDb.OleDbConnection.InitializeProvider() at System.Data.OleDb.OleDbConnection.Open() at Wtest1.WebForm1.ImportData() in C:\Documents and Settings\jayCore\VSWebCache\MXD54406K2\Wtest1\ExcelWebForm.aspx.vb:line 87

    Wednesday, December 26, 2007 1:47 PM

Answers

  • Microsoft limit what you can do with Excel in a web application, you can only read the file not write to it.  The permissions issues are related to IIS6 configuration by default to render static html pages and everything locked down.  The easy option is to run aspnet_regiis and to see if it works, the hard option is to follow the steps in the thread below.  The reason IIS6 is locked down most access is disabled by default including Asp.net.   One more thing in Windows authentication avoid deny because anonymous users are not members of the default everybody group but Asp.net is still a member of the everybody group so if you deny that group Asp.net cannot run.   Hope this helps.

     

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2017178&SiteID=1

     

    Wednesday, December 26, 2007 7:56 PM
  •  George Wang wrote:

    Hi Jay,

     

    The authentication settings in Web.config file only specifies who can bring up your web page, not who is allowed to access other resources. On Windows Server 2003, ASP.NET application by default runs as "NETWORK SERVICE" account, so it is this user account which accesses the resources, and which you need to troubleshoot, when there is a problem.

     

    It is not that simple when Asp.net is reading a file in a Network drive below are the default permissions in IIS 6.

     

    http://support.microsoft.com/kb/812614

    Thursday, December 27, 2007 12:03 AM

All replies

  • The system account that your ASP.NET application runs with (NETWORK SERVICE on win2003) does not have access to the network folder on your file server.

     

    It is not very clear whether your web server and the file server (\\sfddev-01) are the same box. If it is, you only need to grant appropriate access rights to the IIS_WPG group. Otherwise, you will have to configure you web application to run with a different "Application Pool", which runs by a domain account. This domain account also has to be a member of IIS_WPG, and need appropriate access rights to your shared folder.

     

    Wednesday, December 26, 2007 2:42 PM
  • Thans you for the reply.

    To test, I am running the app from my local machine and the excel file I am trying to open is in the network drive.

    I gave IIS_WPG read and write permission to the folder ( to test, I gave full control to IIS_WPG and ASPNET account).

    Still I get the same error.

     

    When the  the webconfig is as shown below, does not mean that any one can access the file?( if the excel file directory is in the same application directory)

    <authentication mode="Windows" />

    <authorization>

            <allow users="*" /> <!-- Allow all users -->

    </authorization>

     

    I can open the same file in the network drive(using the same connection string) using a windows application.

    So I guess, this must be a permission issue, as you pointed out.

     

    Wednesday, December 26, 2007 4:30 PM
  • I moved the web page to the webserver(excel file is also in the same server)

    Now I get this error.

    The Microsoft Jet database engine cannot open the file '\\sfddev-01\e$\wwwroot\ignet\dodworld\webapplications\test\test.xls’. It is already opened exclusively by another user, or you need permission to view its data.

     

    This is the account it uses

    Dim id As WindowsIdentity = WindowsIdentity.GetCurrent

            Response.Write("<B>Identity Check<b>")

            Response.Write("Name: " + id.Name + "<br>")

    Output:

    Identity CheckName: NT AUTHORITY\NETWORK SERVICE

     

    So I gave NETWORK SERVICE ,IIS_WPG and ASPNET also read and write permission. Still no luck Sad

     

    Wednesday, December 26, 2007 5:50 PM
  • Hi Jay,

     

    The authentication settings in Web.config file only specifies who can bring up your web page, not who is allowed to access other resources. On Windows Server 2003, ASP.NET application by default runs as "NETWORK SERVICE" account, so it is this user account which accesses the resources, and which you need to troubleshoot, when there is a problem.

    Wednesday, December 26, 2007 7:54 PM
  • Microsoft limit what you can do with Excel in a web application, you can only read the file not write to it.  The permissions issues are related to IIS6 configuration by default to render static html pages and everything locked down.  The easy option is to run aspnet_regiis and to see if it works, the hard option is to follow the steps in the thread below.  The reason IIS6 is locked down most access is disabled by default including Asp.net.   One more thing in Windows authentication avoid deny because anonymous users are not members of the default everybody group but Asp.net is still a member of the everybody group so if you deny that group Asp.net cannot run.   Hope this helps.

     

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2017178&SiteID=1

     

    Wednesday, December 26, 2007 7:56 PM
  •  George Wang wrote:

    Hi Jay,

     

    The authentication settings in Web.config file only specifies who can bring up your web page, not who is allowed to access other resources. On Windows Server 2003, ASP.NET application by default runs as "NETWORK SERVICE" account, so it is this user account which accesses the resources, and which you need to troubleshoot, when there is a problem.

     

    It is not that simple when Asp.net is reading a file in a Network drive below are the default permissions in IIS 6.

     

    http://support.microsoft.com/kb/812614

    Thursday, December 27, 2007 12:03 AM
  • Next time if you have an issue with ASP.net, Recommend posting the question on the forum http://forums.asp.net, there ASP.net experts can give you satisfying answers.
    Thursday, December 27, 2007 12:50 AM