+ Reply to Thread
Results 1 to 4 of 4

Thread: [C#] SQLite not working correctly.

  1. #1
    Shadow121's Avatar
    Shadow121 is offline x10 Lieutenant Shadow121 is an unknown quantity at this point
    Join Date
    Jul 2006
    Location
    Centerville
    Posts
    455

    [C#] SQLite not working correctly.

    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.

  2. #2
    GtoXic is offline x10 Lieutenant GtoXic is an unknown quantity at this point
    Join Date
    Apr 2010
    Posts
    447

    Re: [C#] SQLite not working correctly.

    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.
    █ x10 Lieutenant
    █ If I have helped, please click the star in the bottom left of my post.

    █ Free Hosting support volunteer 410 posts from Community Advocate (This is NOT live!)


  3. #3
    Shadow121's Avatar
    Shadow121 is offline x10 Lieutenant Shadow121 is an unknown quantity at this point
    Join Date
    Jul 2006
    Location
    Centerville
    Posts
    455

    Re: [C#] SQLite not working correctly.

    This is part where I say thank you a lot and claim this topic as resolved.

  4. #4
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: [C#] SQLite not working correctly.

    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 by misson; 06-21-2011 at 11:03 PM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

+ Reply to Thread

Similar Threads

  1. ASP not working correctly for me
    By unloco in forum Free Hosting
    Replies: 3
    Last Post: 11-20-2010, 10:43 AM
  2. Domain Not Working Correctly
    By duraclean in forum Free Hosting
    Replies: 3
    Last Post: 06-20-2009, 05:07 PM
  3. PHP not working correctly
    By furihh in forum Free Hosting
    Replies: 5
    Last Post: 11-11-2007, 10:18 PM
  4. my IPB not working correctly
    By religionROX in forum Scripts & 3rd Party Apps
    Replies: 1
    Last Post: 06-04-2006, 10:53 PM
  5. site not working correctly
    By Derek in forum Free Hosting
    Replies: 0
    Last Post: 11-19-2005, 02:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers