none
Cannot Start your application.The Workgroup information file is missing or opened exclusively by another user

    Question

  • I have a window form application moving files from different servers and savinge the files information to an Access Datatbase. However, it moves files but cannot insert the information to database due to the error:Cannot Start your application.The Workgroup information file is missing or opened exclusively by another user

    I have searched web and teh forum, and tried to find ways such as modify my connection string. But none of them works.

    Here is the code:

     private void btnProcessSelectedFiles_Click(object sender, EventArgs e) 
      {             
          try 
          { 
             safeTokenHandle = GetSafeHandle(); 
             using (safeTokenHandle) 
                  { 
              WindowsIdentity newId = new indowsIdentity(safeTokenHandle.DangerousGetHandle()); 
              using (WindowsImpersonationContext impersonatedUser = newId.Impersonate()) 
              { 
                    foreach (DataRow row in DPSelectedFilesDataTable.Rows) 
                    { 
                        string name = row["File Name"].ToString(); 
                        string modifiedName = row["Modified Name"].ToString(); 
                        string fullName = Path.Combine(row["Path"].ToString(), name); 
                        string path = row["Path"].ToString(); 
                        string submittedPath = Path.Combine(path, "_submitted"); 
                        string modifiedFilePath = Path.Combine(Settings.Default.DirectoryLocationToResubmitPrintFile, modifiedName); 
                        Directory.CreateDirectory(submittedPath);                     
                        File.Copy(fullName, modifiedFilePath); 
                         
                        File.Move(fullName, Path.Combine(Path.Combine(path, "_submitted"), modifiedName)); 
                        string connectionString = GlobalLoginClass.ConnectionString; 
                        object[] sqlStr = new object[9]; 
                        sqlStr[0] = "INSERT INTO mytable (UserName, FileName, Reason, PDate) VALUES ('"; 
                        sqlStr[1] = GlobalLoginClass.GlobalLoginUserName; 
                        sqlStr[2] = "','"; 
                        sqlStr[3] = name; 
                        sqlStr[4] = " || "; 
                        sqlStr[5] = modifiedName; 
                        sqlStr[6] = "', 'save', '"; 
                        sqlStr[7] = DateTime.Now; 
                        sqlStr[8] = "')"; 
                        string insertSql = string.Concat(sqlStr); 
                        InsertRow(connectionString, insertSql); //fail
                     }//foreach 
     
                        Application.DoEvents(); 
     
                        }//usingimpersoanetUser 
                    }//safetoken 
                   }//try 
                catch (Exception exp) 
                { 
                    MessageBox.Show("Processing has error: \n" + exp.Message, "My App", MessageBoxButtons.OK); 
                } 
            } 
    public void InsertRow(string connectionString, string insertSQL) 
            { 
                using (OleDbConnection oleDbConnection = new OleDbConnection(connectionString)) 
                { 
                    OleDbCommand oleDbCommand = new OleDbCommand(insertSQL); 
                    oleDbCommand.Connection = oleDbConnection; 
     
                    try 
                    { 
                        oleDbConnection.Open(); 
                        oleDbCommand.ExecuteNonQuery(); 
                        oleDbConnection.Close(); 
                    } 
                    catch (Exception exception) //get the error
                    { 
                        MessageBox.Show("Insert your data to database failed: \n" + exception, "My App", MessageBoxButtons.OK); 
                        throw exception; 
                    } 
                } 
            }

    If I remove impersonate user information from the code, it moves files and saves the data to database. But sometimes not always, it gives me error like: Could not find a part of the path

    How can I resolve the problem? Your help is appreciated.

    Tuesday, March 06, 2012 6:21 PM

Answers

  • Hi AiZhu,
    According to MSDN, this error message returned by the Microsoft OLE DB Provider for Jet indicates one of the following:
    The Microsoft® Access database is not a secured database and the login and password specified was not Admin with no password. 
    The Access database is secured and the HKEY_LOCAL_MACHINE\Software\Microsoft\Jet\4.0\SystemDB registry key is not pointing to the correct Access workgroup file. Secured Access databases have a corresponding workgroup file, including the full path, which should be indicated by the above registry key.
    Please take the action in the link below:
    http://msdn.microsoft.com/en-us/library/aa238103(v=sql.80).aspx
    Based on this information, I think maybe the error was in your connection string, please check it with Connection String Syntax (ADO.NET).
    You might also try Michael’s suggestion here.
    Please let me know the result.
    Best Regards,

    Bob Wu [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, March 08, 2012 5:25 AM