title: How to copy Access table to SQL table in C#?
body: <p>As title says I've used odbcconnection to sqlconnection and for the life of me cant get it to work.. Copied a bunch of code from this site but cant get them both to work.</p>
  
  <p>The program just hangs so maybe I am doing something wrong, but would appreciate maybe a bare bones template that i could just fill in the connection details and bulk copy the table to table..</p>
  
  <pre><code> using (OdbcConnection myConnection = new OdbcConnection())
              {
                  string myConnectionString = @"Driver={Microsoft Access Driver (*.mdb)};" +
   "Dbq=//####/data/Toronto/wrkgrp/wrkgrp30/Business Risk Oversight and Control/DATA INTEGRITY/CDE/CDE Testing Portal Requirements/Migration Requirements/RCM/Mutual Funds/Mutual Funds.mdb;";
  
                  myConnection.ConnectionString = myConnectionString;
                  myConnection.Open();
  
                  //execute queries, etc
                  OdbcCommand cmd = myConnection.CreateCommand();
  
                  cmd.CommandText = "SELECT * FROM RCM_MF_New_Accounts_Samples";
                  OdbcDataReader reader = cmd.ExecuteReader(); // close conn after complete
  
                  DataTable myDataTable = new DataTable();
                  myDataTable.Load(reader);
                  //myConnection.Close();
  
                  string destinationConnectionString = "Data Source=####;Initial Catalog=DYOF_STAGING_BROC;User ID=;Password=;Connection Timeout=999";
  
                  SqlConnection destination = new SqlConnection(destinationConnectionString);
                  SqlBulkCopy bulkData;
                  //destination.Open();
  
                  Exception ex = null;
                  try
                  {
                      Console.WriteLine("step1");
                      bulkData = new SqlBulkCopy(destinationConnectionString, SqlBulkCopyOptions.FireTriggers);
                      bulkData.BulkCopyTimeout = 1;
                      bulkData.DestinationTableName = "Load_CTR_Sample_Account_Opening2";
                      bulkData.WriteToServer(myDataTable);
                      bulkData.Close();
                      Console.WriteLine("moved from here to there");
                      reader.Close();
  
                      //destination.Close();
  
  
                  }
                  catch (Exception e)
                  {
                      ex = e;
                  }
  </code></pre>