edit2: solution http://stackoverflow.com/questions/1710941/sqlite-and-object-reference-not-set-exception/1711481#1711481
I am having a hard time understanding my error.
edit1: I set my define to make my code single threaded. The problem went away. So it seems like a race condition.
I get the error below. But not always, i notice that if i do not set a break or i step through them quickly i get no exception. When set a breakpoint at var o = command.ExecuteScalar();
or the line before it and wait 10+ seconds (i used the system clock to check, not counting) it will ALLWAYS get an exception (i tried it twice however based on what i notice the exception happens only when i break for more then a few seconds).
I dont understand WHY i am getting the error. I printed out both the sql statement and the param values i fed it and i can see its correct values. Whats going on!?! and what bothers me is the COUNT(*) works but the insert doesnt.
Here is my code
else
{
command.CommandText = "SELECT COUNT(*) FROM link_list;";
var o = command.ExecuteScalar();
int status = (int)r.status;
command.CommandText = "UPDATE link_list SET status=@status WHERE id=@id;";
command.Parameters.Add("@status", System.Data.DbType.Byte).Value = status;
command.Parameters.Add("@id", System.Data.DbType.Int32).Value = info.linkId;
Console.WriteLine("CommandText {0} {1} {2}", command.CommandText, status, info.linkId);
command.ExecuteNonQuery();
Console.WriteLine("CommandText no exception");
}
elsewhere
catch(Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
My output
CommandText UPDATE link_list SET status=@status WHERE id=@id; 5 108
The thread '<No Name>' (0xbc8) has exited with code 0 (0x0).
A first chance exception of type 'System.NullReferenceException' occurred in System.Data.SQLite.dll
Object reference not set to an instance of an object.
at System.Data.SQLite.SQLiteDataReader.NextResult()
at System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior behave)
at System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.SQLite.SQLiteCommand.ExecuteNonQuery()
at WebDLManager.DB.updateStatus(DLInfo info, ReturnVal r) in C:\dev\source\prvTrunk\WebDLManager\WebDLManager\db.cs:line 134
at WebDLManager.SiteBase.threadStart() in C:\dev\source\prvTrunk\WebDLManager\WebDLManager\SiteType.cs:line 241
The program '[1360] WebDLManager.vshost.exe: Managed' has exited with code 0 (0x0).
As requested
//this is called through form_load
connection = new SQLiteConnection("Data Source=mydb.sqlite3;Version=3");
command = new SQLiteCommand(connection);
connection.Open();