I suggest that you use Transactions to perform this command sequence. This way, you will ensure single-table access:
OleDbConnection.BeginTransaction Home
Starts a transaction in the database with the possibility of specifying the type of transaction isolation.
Isolation Mode Home
- IsolationLevel.Serializable = Prevents other users update, or insert rows in the range is being changed until the transaction completes.
Code
using (OleDbConnection conn = new OleDbConnection(Conexao.getConexaoPainelGerencialLocal())) {
OleDbCommand cmd = new OleDbCommand();
OleDbTransaction transaction = null;
cmd.Connection = conn;
// Abre a conexão e inicia a transação
try {
conn.Open();
// Inicia uma transação
transaction = conn.BeginTransaction(IsolationLevel.Serializable);
cmd.Connection = conn;
cmd.Transaction = transaction;
cmd.CommandText = "DELETE * FROM tblClienteContato";
cmd.ExecuteNonQuery();
//nesse meio tempo, NINGUÉM poderá efetuar qualquer operação na tabela tblClienteContato até que a transação seja finalizada
cmd.CommandText = " INSERT INTO tblClienteContato " +
" SELECT * FROM tblClienteContatoVinculada;";
cmd.ExecuteNonQuery();
// Efetiva a transação
transaction.Commit();
}
catch (Exception ex) {
Console.WriteLine(ex.Message); //exibe no console o erro
try {
// Se der algum erro (no delete ou insert) desfaz as alterações
transaction.Rollback();
}
catch {
}
}
//Aqui a conexão já estará fechada
}
Highly Recommended Reading
Transactions and Concurrency