Bulk copy from MS Access to SQL Server
<p>I'm trying to copy tables form a MS Access database into a SQL Server database.</p>

<p>This is the code:</p>

<pre><code>private static void BulkCopyAccessToSQLServer(string sql, string destinationTable,string fileName)
{
  using (DataTable dt = new DataTable())
  {
     using (OleDbConnection conn = new OleDbConnection(String.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}", fileName)))
     using (OleDbCommand cmd = new OleDbCommand(sql, conn))
     using (OleDbDataAdapter adapter = new OleDbDataAdapter(cmd))
     {
         cmd.Connection.Open();
         adapter.SelectCommand.CommandTimeout = 240;
         adapter.Fill(dt);
         adapter.Dispose();
     }
     using (SqlConnection conn2 = new SqlConnection(connStr))
     {
         conn2.Open();
         using (SqlBulkCopy copy = new SqlBulkCopy(conn2))
         {
             copy.DestinationTableName = destinationTable;
             copy.BatchSize = 1000;
             copy.BulkCopyTimeout = 240;
             copy.WriteToServer(dt);
             copy.NotifyAfter = 1000;
         }
     }
  }
}
</code></pre>

<p>Calling this function like this...</p>

<pre><code>BulkCopyAccessToSQLServer("select * from Table1", "Table1", "C:\\db.‌​accdb");
</code></pre>

<p>I get the following error:</p>

<blockquote>
  <p>System.Data.OleDb.OleDbException: Could not find file 'C:\db.‌​accdb'.<br>
  at System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString
  constr, OleDbConnection connection)<br>
  at System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions
  options, Object poolGroupProviderInfo, DbConnectionPool pool,
  DbConnection owningObject)<br>
  at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection
  owningConnection, DbConnectionPoolGroup poolGroup)<br>
  at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection
  owningConnection)<br>
  at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection
  outerConnection, DbConnectionFactory connectionFactory)<br>
  at System.Data.OleDb.OleDbConnection.Open()<br>
  at WebService.BulkCopyAccessToSQLServer(String sql, String destinationTable, String fileName)<br>
  at WebService.Import()</p>
</blockquote>

<p>What am I doing wrong?</p>
