[C#] SQLite not working correctly.

Shadow121

Member
Messages
901
Reaction score
0
Points
16
I'm working on a bot for something and I keep hitting blanks and getting an error. I asked a friend of mine for help but he couldn't find the issue.

The code is:
Code:
sqlConn = new SQLiteConnection("Data Source=botinfo.db;Version=3;New=False;Compress=True;Journal Mode=Off;");
                sqlConn.Open();
                sqlComm = new SQLiteCommand();
                sqlComm.Connection = sqlConn;
                sqlComm.CommandText = "DELETE FROM bot_controllers WHERE controller_name = '" + controllerName + "';";
                sqlComm.ExecuteNonQuery();
                sqlConn.Close();

sqlConn and sqlComm are defined at the top of the file. They are assigned in this function.

The problem:
Code:
System.NullReferenceException: Object reference not set to an instance of an obj
ect.
   at System.Data.SQLite.SQLite3.Prepare(SQLiteConnection cnn, String strSql, SQ
LiteStatement previous, UInt32 timeoutMS, String& strRemain)
   at System.Data.SQLite.SQLite3.Reset(SQLiteStatement stmt)
   at System.Data.SQLite.SQLite3.Step(SQLiteStatement stmt)
   at System.Data.SQLite.SQLiteDataReader.NextResult()
   at System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavi
or behave)
   at System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior)
   at System.Data.SQLite.SQLiteCommand.ExecuteNonQuery()
   at FurcBot.Classes.botSockets.removeController(String controllerName) in C:\U
sers\Joseph\documents\visual studio 2010\Projects\ConsoleApplication1\ConsoleApp
lication1\Classes\botSockets.cs:line 435

Any insight or help would be appreciated.
 

GtoXic

x10 Support
Messages
636
Reaction score
17
Points
0
Howdy, You'll want to check that each var is defined in that code, just keep doing that until you don't encounter an error. That'll make it alot easier to know what's causing it.
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
My first piece of advice is to use LINQ rather than writing out SQL queries. Heck, even ADO would be better. If you insist on writing the SQL statements yourself, at least use a prepared statement and parameterize the value for controller_name. For one thing, if there's a problem with the value stored in controllerName, you'll get a more appropriate error.

Since the sample code isn't complete, I can't test it nor say what's wrong with it, and I don't have the time to fill it out (which wouldn't even then be guaranteed to exhibit the same issue).
 
Last edited:
Top