Reopening of connection for every query

Topics: Windows Phone
Jun 23, 2015 at 11:11 AM
I close the connection (Dispose() ) after performing every query. The problem is subsequent update query is not getting updated in the DB.

I have a DBManager class which implements IDisposable interface. The class has a sql_conn variable. It has an OpenConnection function which creates a new connection. The class also has functions to create tables, update record etc.
public DBManager()
{
   sql_conn = new SQLiteConnection("MyDB.db");
}

public void Dispose()
{
   sql_conn.Dispose();
}
Every time I need to update some value, I create an object of DBMan and open connection
using (DBManager dbMan = new DBManager())
{
   dbMan.OpenConnection();
   dbMan.InsertIntoDB(val1, val2);  
}
Since DBManager has implemented IDisposable, it disposes the sql_conn after the using statement is completed.

The problem I'm now facing is, in one of the classes I'm required to update several values of the same row based on the certain checks.
void SaveValues
{
 save1();
 save2();
 save3();
}
In save1, I open the connection, update record and close connection In save2, I open connection and update record and then close.
public void save1()
{
   using (DBManager dbMan = new DBManager())
   {
       dbMan.OpenConnection();
       if(//check)
       {
       dbMan.InsertIntoDB(val1, val2);// update query is used  
       }
   }
}

public void save2()
{
    using (DBManager dbMan = new DBManager())
    {
       dbMan.OpenConnection();
       if(//check)
       {
       dbMan.InsertIntoDB(val3, val4);  
       }
    }
}
Save1 works and the value is updated in db. But save2 is not. The function does not throw error but it does not update value in DB.