locked
file is already opened exclusively by another user, or you need permission to view its data. RRS feed

  • Question

  • User351619809 posted

     It is already opened exclusively by another user, or you need permission to view its data.

    private void CreateDBFFile()
    {
        string connection = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
    
        using (OleDbConnection dbconnection = new OleDbConnection(connection))
        using (OleDbCommand command = dbconnection.CreateCommand())
        {
            dbconnection.Open();
    
            command.CommandText = "CREATE TABLE Test (Id Integer, Changed Double, Name Text)";
            command.ExecuteNonQuery();
        }
    }

    My web.config file has connection string

    <connectionStrings>
      <add name="conn"
           connectionString="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=k:\temp1" 
           providerName="System.Data.OleDb" />
    </connectionStrings>

    I am trying to create a dbf file on my K drive. I keep getting an error on my dbConnection.Open() statement saying:

    The Microsoft Jet database engine cannot open the file 'k:\temp1'. It is already opened exclusively by another user, or you need permission to view its data.

    K:\ is not a mapped drive. I gave network service userName to temp1 folder by going under security tab. I also gave modify rights to the Network service. Still keep getting this error. I also tried to put the entire above code in console application, that didn't work either. I keep getting the same error.

    Any help will be greatly appreciated.

    Tuesday, June 27, 2017 7:54 PM

All replies

  • User2053451246 posted

    Think about the user Visual Studio/IIS is using to run your site.  Does that user have access to that folder?  If you are sure the file is there I would temporarily give permissions to all users for that folder and then test.

    Also, why is there no file extension in your connection string?

    Tuesday, June 27, 2017 8:06 PM
  • User351619809 posted

    I am trying to create a .dbf file. in the temp1 folder.

    Tuesday, June 27, 2017 8:14 PM
  • User2053451246 posted

    Did you try my suggestion???

    Tuesday, June 27, 2017 8:50 PM
  • User-158764254 posted

    I keep getting an error on my dbConnection.Open() statement saying:

    The Microsoft Jet database engine cannot open the file 'k:\temp1'. It is already opened exclusively by another user, or you need permission to view its data.

    If you are missing the Extended Properties attribute, you can encounter that error. Change your connection string like this:

    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=k:\temp1;Extended Properties=dBase IV"

    Tuesday, June 27, 2017 10:11 PM
  • User351619809 posted

    I put the Extended properties in my connection string and it looks like below

    <connectionStrings>
        <add name="conn" connectionString="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=k:\temp1; Extended Properties=dBase IV" providerName="System.Data.OleDb"  />
    
      </connectionStrings>

    When I tried running it, the code terminates at the line below:

       dbconnection.Open();

    It does not throw any error. I didn't change the code at all:

      private void CreateDBFFile()
            {
    
    
                string connection = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
    
            
    
    
                using (OleDbConnection dbconnection = new OleDbConnection(connection))
                using (OleDbCommand command = dbconnection.CreateCommand())
                {
                    dbconnection.Open();
    
                    command.CommandText = "CREATE TABLE Test (Id Integer, Changed Double, Name Text)";
                    command.ExecuteNonQuery();
                }
    
    
    
            }

    any help will be appreciated.

    Tuesday, June 27, 2017 10:35 PM
  • User351619809 posted

    The above code is working on different computer, but not on my office computer. Can anyone tell me what file went corrupt that the above code is not working on my office computer. IT is working fine on my home computer,

    Wednesday, June 28, 2017 2:37 AM
  • User753101303 posted

    Hi,

    You really don't have any error even in the Windows event log? Could it be that Microsoft.Jet.OLEDB.4.0  is not installed (also it works only in 32 bit mode)?

    Wednesday, June 28, 2017 11:07 AM
  • User351619809 posted

    This is the error from event viewer

    Faulting application name: iisexpress.exe, version: 10.0.14358.1000, time stamp: 0x574fc56b
    Faulting module name: clr.dll, version: 4.6.1649.1, time stamp: 0x58f97fe6
    Exception code: 0xc0000005
    Fault offset: 0x0045068d
    Faulting process id: 0x425c
    Faulting application start time: 0x01d2f037cca36f3a
    Faulting application path: C:\Program Files (x86)\IIS Express\iisexpress.exe
    Faulting module path: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
    Report Id: 0d0ddc31-5c2b-11e7-b3f6-005056c00008

    I guess I need to replace clr.dll and it should start working

    Wednesday, June 28, 2017 5:56 PM