0

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

1
  • Can this action be done when From DB is not protected in a SYSTEM.MDW? I would guess you need the Access environment to be opened, and run the INSERT statement. I may be wrong, of course... Commented May 5, 2016 at 12:11

1 Answer 1

0

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;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.