title: Losing my Access DB password on compact, how to reset from VB?
body: <p>First time poster here...</p>
  
  <p>My VB.NET program compacts and repairs my DB, but somewhere in the process unsets the database password. No problem, just reset it through VB, right? Ummm... not sure how to go about that task. </p>
  
  <p>So I either need to know how to compact it without losing the password, or how to reset the password after I lose it. </p>
  
  <p>Trying the best I can to make the code look decent in my post, let me know if there is a better way.</p>
  
  <p>Thanks!</p>
  
  <pre><code>Dim strAccessDatabasePath As String = System.AppDomain.CurrentDomain.BaseDirectory &amp; "App_Data\Squirrel.accdb"        
  Dim LockedDbFileInfo As New System.IO.FileInfo(strAccessDatabasePath.Replace(".accdb", ".laccdb"))        
  Dim TempFolder As String = System.AppDomain.CurrentDomain.BaseDirectory &amp; "App_Data\temp"        
  Dim TempDB As String = TempFolder &amp; "\temp.accdb"
  
  If LockedDbFileInfo.Exists Then            
      MsgBox("Database is in use. Please make sure no users are in the database before performing maintenance.")        
  Else            
      MsgBox("This program has detected no current database users and will proceed with database maintenance.")        
  End If  
  
  Try            
      Directory.CreateDirectory(TempFolder)        
  Catch ex As Exception            
      MsgBox("There has been an error creating a temporary directory in your application directory. Please check credentials and try again.")        
  End Try  
  
  Dim time As DateTime = DateTime.Now        
  Dim format As String = "MMM d yyyy HHmmss "        
  Dim TempDateTime As String = time.ToString(format)         
  
  'Copy DB to backup directory.        
  Try            
      File.Copy(strAccessDatabasePath, txtDBbackupFolder.Text &amp; "\" &amp; "DBbkup " &amp; TempDateTime &amp; ".accdb")        
  Catch ex As Exception            
      MsgBox("There was an issue writing to the backup folder. Please check credentials and try again.")        
  End Try    
  
  'Copy DB to temp directory for maintenance.        
  File.Copy(strAccessDatabasePath, TempFolder &amp; "\" &amp; "temp.accdb")        
  File.Delete(strAccessDatabasePath)         
  Dim JROEng As Object         
  JROEng = CreateObject("JRO.JetEngine")         
  JROEng.CompactDatabase("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" &amp; TempDB &amp; ";Jet OLEDB:Database Password=woodkitten70;Jet OLEDB:Engine Type=5", "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" &amp; _
  strAccessDatabasePath &amp; ";Jet OLEDB:Engine Type=5")         
  'connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\App_Data\Squirrel.accdb;Jet OLEDB:Database Password=XXXXXXXXX" 
  
  Try            
      Kill(TempFolder &amp; "\*.*")        
  Catch ex As Exception            
      'MsgBox(ex.Message)        
  End Try         
  Directory.Delete(TempFolder)`
  </code></pre>