title: Merging two SQLite database files (C# .NET)
body: <p>I'm using C#/.NET with the C# wrapper for SQLite. I'm attempting to merge two SQLite databases together while excluding duplicates.</p>
  
  <p>I found this, which is referenced from a few different forum questions. <a href="http://old.nabble.com/Attempting-to-merge-large-databases-td18131366.html" rel="noreferrer">http://old.nabble.com/Attempting-to-merge-large-databases-td18131366.html</a></p>
  
  <p>I've tried the below queries, which I structured from the link I provided, but they result in exceptions, the databases are not merged at all, and the original database is not changed whatsoever.</p>
  
  <pre><code>attach 'c:\test\b.db3' as toMerge;   
  insert into AuditRecords select * from toMerge.AuditRecords; 
  </code></pre>
  
  <p>Here is my query code.</p>
  
  <pre><code>public void importData(String fileLoc)
      {
          SQLiteTransaction trans;
          string SQL = "ATTACH '" + fileLoc + "' AS TOMERGE";
          SQLiteCommand cmd = new SQLiteCommand(SQL);
          cmd.Connection = connection;
          connection.Open();
          trans = connection.BeginTransaction();
          int retval = 0;
          try
          {
              retval = cmd.ExecuteNonQuery();
          }
          catch (Exception)
          {
              trans.Rollback();
              MessageBox.Show("An error occurred, your import was not completed.");
          }
          finally
          {
              trans.Commit();
              cmd.Dispose();
              connection.Close();
          }
  
          SQL = "INSERT INTO SUBCONTRACTOR SELECT * FROM TOMERGE.SUBCONTRACTOR";
          cmd = new SQLiteCommand(SQL);
          cmd.Connection = connection;
          connection.Open();
          trans = connection.BeginTransaction();
          retval = 0;
          try
          {
              retval = cmd.ExecuteNonQuery();
          }
          catch (Exception)
          {
              trans.Rollback();
              MessageBox.Show("An error occurred, your import was not completed.");
          }
          finally
          {
              trans.Commit();
              cmd.Dispose();
              connection.Close();
          }
      }
  </code></pre>
  
  <p>My question is, what am I doing wrong? And is anyone familiar with the insert command? I'm unsure if it will exclude duplicates as I need.</p>