Reputation: 3
I am trying to import data from one MS Access database into another MS Access database and have found the following works fine, problem I have got is does anybody know what I should be using if the from database is locked with a SYSTEM.MDW
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Data\Database1.mdb;User Id=admin;Password=;";
string commandText = "INSERT INTO [TableName] SELECT * FROM [MS Access;DATABASE=C:\\Data\Database2.mdb].[TableName]";
try
{
using (OleDbConnection oleConnection = new OleDbConnection(connectionString))
{
using (OleDbCommand oleCommand = new OleDbCommand(commandText, oleConnection))
{
oleCommand.CommandType = CommandType.Text;
oleCommand.Connection.Open();
oleCommand.ExecuteNonQuery();
}
}
}
catch (Exception)
{
throw;
}
I can open the From database using Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Data\Database2.MDB;System Database=C:\Data\SYSTEM.MDW;User ID=Developer;Password=Password
Upvotes: 0
Views: 120
Reputation: 1485
If you can open the From database, open it and do the action from it:
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Data\Database2.MDB;System Database=C:\Data\SYSTEM.MDW;User ID=Developer;Password=Password";
string commandText = "INSERT INTO [TableName] In 'C:\\Data\Database1.mdb' SELECT * FROM [TableName]";
try
{
using (OleDbConnection oleConnection = new OleDbConnection(connectionString))
{
using (OleDbCommand oleCommand = new OleDbCommand(commandText, oleConnection))
{
oleCommand.CommandType = CommandType.Text;
oleCommand.Connection.Open();
oleCommand.ExecuteNonQuery();
}
}
}
catch (Exception)
{
throw;
}
Upvotes: 0