SQLite error - Please Help (1 Viewer)

Hesse

Portal Pro
August 8, 2006
110
0
I'm having some issues with SQLite and my class. Here is a portion of a class that I wrote called GENERAL_DB which is supposed to be the class which can access the SQLite DB. I have a separate test block of code which attempts to create an instance of this class and open the database as shown.

However, when I run the code, I get an exception that I can't understand why its occurring. When I run in debug mode and step through, it bombs on the line

Code:
m_db = new SQLiteClient(databaseFile);

with the exception

Code:
{"Object reference not set to an instance of an object."}

I thought that I was setting the instance there?? Can anyone help me out?

Regards,

Jesse


--- GENERAL_DB class ----

Code:
using System;
using System.Data;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.Windows.Forms;
using MediaPortal.Database;
using SQLite.NET;


namespace GUIXMM
{
  public class GENERAL_DB
  {
    public SQLiteClient m_db = null;
    private bool dbExists;

    public GENERAL_DB()
    {
    }

    public void Open()
    {
      

      // Attempt to open database
      try
      {
        // Open database
        MessageBox.Show("Open DB");

        string fullpath = "C:\\Program Files\\Team MediaPortal\\MediaPortal\\";
        string databaseFile = fullpath + "database\\VideoDatabaseV5.db3";
        dbExists = System.IO.File.Exists(databaseFile);

        Console.WriteLine("dBExists: " + dbExists.ToString());

        m_db = new SQLiteClient(databaseFile);

        if (!dbExists)
        {
          Console.WriteLine("DB does not exist, creating tables.");
          //CreateTables();
        }
      }
      catch (SQLiteException ex)
      {
        Console.WriteLine("Fatal error: {0}", ex.Message);
        //Log.Write("XMMdatabase exception err:{0} stack:{1}", ex.Message, ex.StackTrace);
      }
    }

  }
}




--- Separate function to create instance of GENERAL_DB ----

Code:
    private void button_debug_VIDEO_DB_Click(object sender, EventArgs e)
    {
      string fullpath = "C:\\Program Files\\Team MediaPortal\\MediaPortal\\";

      string database = fullpath + "database\\VideoDatabaseV5.db3";
      //MessageBox.Show(database);

      if (File.Exists(database))
      {
        MessageBox.Show("File: " + database + " exists");
      }
      else
      {
        MessageBox.Show("File: " + database + "was not found.");
      }

      //VIDEO_DB myVIDEO_DB = new VIDEO_DB();
      //myVIDEO_DB.Open();

      GENERAL_DB myGENERAL_DB = new GENERAL_DB();
      myGENERAL_DB.Open();

    }
 

Markus1972

Portal Pro
March 17, 2006
73
0
Hi,

i don't know much about SQLLient. But when u use OLeDB, you need to set the full path into the Constructor. if you don't do this, you get your Error Message. Perhaps here ist the same situation
 

Hesse

Portal Pro
August 8, 2006
110
0
Hi Markus1972,

What do you mean by full path to the constructor? I am using the full path to the database file. You mean like SQLite.NET.SQLiteClient?
 

samuel337

Portal Pro
August 25, 2004
772
0
Melbourne, Australia
Markus1972 was just referring to your initial code snippet, where your wrote

m_db=new SQLiteClient("VideoDatabaseV5.db3");

instead of

m_db=new SQLiteClient(@"C:\Program Files\Team MediaPortal\MediaPortal\Databases\VideoDatabaseV5.db3");

Anyway, what's the rest of the information for that exception, i.e. the trace of where the exception occurred?

Sam
 

Hesse

Portal Pro
August 8, 2006
110
0
Markus1972 was just referring to your initial code snippet, where your wrote

m_db=new SQLiteClient("VideoDatabaseV5.db3");

instead of

m_db=new SQLiteClient(@"C:\Program Files\Team MediaPortal\MediaPortal\Databases\VideoDatabaseV5.db3");

Anyway, what's the rest of the information for that exception, i.e. the trace of where the exception occurred?

Sam

I misquoted the exception line. If you look in the code, it actually calls the full path to the database file. The problem is very strange. It traces back to the MediaPortal.Database file which is expected since that is where SQLite.NET resides. However, I tried debugging some other peoples code (MyTVseries and MyDVDs) and I get the same exception on their code even though we know that it compiles and runs correctly since their code works.

Can this exception be a problem with debugging with SQLite?

Basically, since I couldn't figure it out, I've turned to using the System.Data.SQLite opensource class located at http://sqlite.phxsoftware.com/. I haven't had any problems with using this code. The only issue is that its harder to use data from a query.

If I can get the built-in SQLite reader working, then great. If not, I'm going to stick with this other method. It follows the standard ADO.NET database access methods, so that is nice.

Jesse
 

samuel337

Portal Pro
August 25, 2004
772
0
Melbourne, Australia
Hmm... interesting. I've always been able to compile the Databases project, in fact just did that last week. That project contains numerous references to SQLiteClient.

Have you referenced the required assemblies? Are you using VS2005 or Express or something else?

Sam
 

Hesse

Portal Pro
August 8, 2006
110
0
Hmm... interesting. I've always been able to compile the Databases project, in fact just did that last week. That project contains numerous references to SQLiteClient.

Have you referenced the required assemblies? Are you using VS2005 or Express or something else?

Sam

Actually, it compiles just fine. What I meant was that if I create a test project that is attached to those projects, then try to create an instance of SQLiteClient just like those projects do, then I get the error. The actual compiling of the DLL files works ok, its only when you actually try to use it...

I am using Visual C# 2005 Express Edition. You can see the referenced assemblies in the code that I have. I think that I referenced all of them correctly. Plus other peoples code that works as a plugin, doesn't work for me in debug mode.
 

samuel337

Portal Pro
August 25, 2004
772
0
Melbourne, Australia
Going through the source code, I found that the SQLite.NET class references sqlite.dll. How are you running this code? Loading it in MP or independently?

If independently, you'll need to make sure sqlite.dll is in the same folder as the executable/assembly.

I think the problem is with how you're debugging the code. VS.NET is probably looking somewhere else for sqlite.dll and it can't find it. Can you tell us how you're debugging the code?

The fact that an SQLiteException isn't being thrown and all the code in the constructor of SQLiteClient is encapsulated in a try-catch statement points to the fact that the class itself isn't being used.

Sam
 

Hesse

Portal Pro
August 8, 2006
110
0
I'm running it independently of MediaPortal. I put the sqlite.dll file that was located in the MediaPortal directory into the debug directory of my project because otherwise it throws an exception saying that it cannot find the sqlite.dll.

I think maybe I've confused you a bit. I can compile MediaPortal source code with no issues. When I run this bit of code (or any other code that actually creates an instance of a SQLite object) in debug mode by stepping through, then C# definately throws an SQLiteException with the error that I originally posted.
 

Hesse

Portal Pro
August 8, 2006
110
0
Ok, I'd like to return to this because I'd like to be able to use the built-in SQLite stuff to match the syntax of other developers.

Please, if you have any information out there, please respond.

It appears that the exception is only related to debugging. On one of the WindowsForms in my plugin I made a button with the following code:

Code:
    private void button_debug_Click(object sender, EventArgs e)
    {
      string strDatabaseFile = textBox_MPDatabaseFile.Text;

      try
      {
        SQLiteClient m_db = new SQLiteClient(strDatabaseFile);
        MessageBox.Show("Successfully opened database.");
      }
      catch
      {
        MessageBox.Show("ERROR. Something happened.");
      }

    }

When I try to run the code in debug mode, it drops to the catch statement because of the errors that I've listed previously.

BUT, when I compile the code and run as a MP plugin, it successfully opens the database. How do you other developers debug your code?? Is there something I'm missing. I copied the SQLite.dll from the MediaPortal directory into the debug folder of my project so that it can find it.

I really want to figure this out because it is really annoying :mad:
 

Users who are viewing this thread

Top Bottom