static void TransferTableData(
String AccessSourcedb,
String DestinationConnectionStr,
String TableName
)
{
//Connection to the destination
SqlConnection DestConnection = new SqlConnection(DestinationConnectionStr);
DestConnection.Open();
SqlCommand Cmd = DestConnection.CreateCommand();
//Connection to source
OleDbConnection OledbSrcConnection = new
System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + AccessSourcedb);
OledbSrcConnection.Open();
// Reader to source
OleDbCommand OleDbCommand = new OleDbCommand("SELECT * FROM " +
TableName);
OleDbCommand.Connection = OledbSrcConnection;
OleDbDataReader OleDbDataReader = OleDbCommand.ExecuteReader();
//bulk upload to destination
SqlBulkCopy bulkCopy = new SqlBulkCopy(DestConnection,
System.Data.SqlClient.SqlBulkCopyOptions.KeepIdentity, null);
bulkCopy.BulkCopyTimeout = 100000000;
bulkCopy.DestinationTableName = TableName;
bulkCopy.WriteToServer(OleDbDataReader);
bulkCopy.Close();
}
Moving data from Access to SQL Server using ADO.NET
Tags:
.Net,
Database,
SQL Server
Generally it is required to copy data from access to sql server. we can do it using sql server services. But here it is performed using .NET.
| Reactions: |
Related Posts :
Subscribe to:
Post Comments (Atom)
Twitter
Facebook
No comments:
Post a Comment