Click here to Skip to main content
15,886,769 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have 3 firebird databases in my project. A master database and 2 slave databases. What I need to do is to save some records in the main database to the slave databases and I have to do this at certain times. For example, every 30 minutes... I am trying to do these operations in c# and it will be a desktop application. As you can guess, I have a timer object in my project, and I repeat these operations at the time interval specified by the user. My problem is this: When the program is first run, all processes work normally. But the second time the timer is triggered the create operations don't work. Update operations work fine. I'm about to go crazy...

If you want to check all codes please go to : github

Thx a lot for your helps...

What I have tried:

Sample create method:

C#
private void CreateProductOnSlave1Database(Product pro)
       {
           string cmd = $"INSERT INTO ARTIKEL(KZPREISAENDERUNG,columnNames) VALUES({pro.KZPREISAENDERUNG},otherValues)";
           FbConnection peterConnection = GetSlave1DatabaseConnection();
           FbTransaction transaction = peterConnection.BeginTransaction("CreateProductOnSlave1");
           FbCommand command = new FbCommand();
           command.CommandType = CommandType.Text;
           command.Connection = peterConnection;
           command.Transaction = transaction;
           command.CommandText = cmd;
           try
           {
               command.ExecuteNonQuery();
               transaction.Commit();
           }
           catch (Exception message)
           {
               transaction.Rollback();
               MessageBox.Show(message.Message);
           }
           finally
           {
               KillDatabaseConnection(peterConnection,command);
           }
       }


C#
public void KillDatabaseConnection(FbConnection connection, FbCommand command)
     {
         command.Dispose();
         connection.Close();
         connection.Dispose();
     }
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900