Thanks for your reply.
I am using version 1.0.79.0 of System.Data.sqlite
Here is how i am using it, i only use executescalar and
executenonquery, let me know if you want to see how i pass the
parameters etc.


RunBigtransaction()
{

         using (IDbTransaction tran = Connection.BeginTransaction())
         {
            foreach (Message msg in messages)
            {
               CreateMessage(msg);
            }
            tran.Commit();
         }
}

                
                 void CreateMessage()
                 {
                  string tableName = gettablename();
                
                  // here i check if a table exists using a select query
          string query = select "name" from "sqlite_master" where
"type=table", name=tablename";
                  string tablename = ExecuteQuery(query)
                
                  if (tablename == null)
                
                  {
                        // here i do a query on another table in schema to read 
a script to
create a new table, which uses the ExecuteGetTableQuery.
                        string script = getscript();
                        Exceute(script);
                  }
                
                  // here i execute an insert and update
                
                  // insert uses the same pattern like ExecuteGetTableQuery but 
with
query changed to insert into with 15 parameters.
                    RawInsertMessage(tableName, msg);
                        
                        // insert or update where update does just Execute 
function.
            SetMessageFolderId(msg.StoreId, msg.Id, msg.ParentId);              
                 }
                
                 public void  Execute(string script)
                 {
                        using (IDbCommand cmd = Connection.CreateCommand())
                        {
                                cmd.CommandText = script;
               cmd.ExecuteNonQuery();
            }
         }              
                
                 public string ExecuteGetTableQuery(string b)
                 {
                         using (IDbCommand cmd = Connection.CreateCommand())
                         {
                                cmd.CommandText = b.ToString();

                                object r = cmd.ExecuteScalar();

                                if (r == null || r is DBNull) return default(T);
                                if (!(r is T)) throw new 
InvalidCastException("cannot cast " +
r.GetType() + " to " + typeof (T));
                                return (T) r;
                         }
                 }




Regards,
Raj


On Thu, Nov 15, 2012 at 8:52 PM, Joe Mistachkin <[email protected]> wrote:
>
> rui wrote:
>>
>> I am seeing explosive memory growth when i am using transactions using
>> System.Data.SQLite.
>>
>
> The best way to address this issue is to utilize "using" blocks for any 
> SQLiteCommand, SQLiteDataReader, and SQLiteTransaction objects used.  That 
> way, you won't have to wait until they are garbage collected later on by the 
> CLR.
>
>>
>> All the object are properly disposed from trasnsaction to command etc.
>>
>
> Could you provide some example C# code that demonstrates the behavior you are 
> seeing?
>
>>
>> The SQLiteConnection is kept open for the life time of the session,
>> which could span hours.
>>
>
> This means the memory associated with the connection will be kept around; 
> however, this should be OK and should not result in the memory usage numbers 
> you are seeing.
>
> --
> Joe Mistachkin <[email protected]>
>
>
> _______________________________________________
> sqlite-users mailing list
> [email protected]
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to