Question

I tried everything, but always , it returns me a System.NullreferencesException at "com.Transaction = trx;"

   public override int ExecuteNonQuery(string query)
    {

        int register=0;
        SQLiteTransaction trx=null;
        SQLiteCommand com;
        try
        {
            if (this.IsClosed()) this.Open();

                trx = con.BeginTransaction();
                com = new SQLiteCommand(query, con);
                com.Transaction = trx;
                register = com.ExecuteNonQuery();
                trx.Commit();

            return register;
        }
        catch (SQLiteException ex)
        {
            trx.Rollback();//se tiene q deshaser toda la trransaccion hecha
            throw ex;
        }

        finally
        {
            this.Close();
        }

    }

i dont figure out where my error is :(

here is the exception that throws me in transaction

Update:

Here are are The Exception Detalis

Was it helpful?

Solution 2

i fix it, the problem was with transaction, i think that sqlite doesn't support that, i commented it and all works like a charm.

  public override int ExecuteNonQuery(string query)
    {

        int register=0;
        //SQLiteTransaction trx=null;
        SQLiteCommand com;
        try
        {
            if (con.State == ConnectionState.Closed) this.Open();

                //trx = con.BeginTransaction();//para hacer transaciones para que la base de datos este estable
                com = new SQLiteCommand(query, con);
                //com.Transaction = trx;
                register = com.ExecuteNonQuery();//recien hacemos la coneccion en esta linea
               // trx.Commit();

            return register;
        }
        catch (SQLiteException ex)
        {
           // trx.Rollback();//se tiene q deshaser toda la trransaccion hecha
            throw ex;
        }

        finally
        {
            this.Close();
        }

    }

OTHER TIPS

Try to replace these lines

 if (this.IsClosed()) 
      this.Open();

with

 if (con.State == ConnectionState.Closed) 
     con.Open();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top