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
with the exception
I thought that I was setting the instance there?? Can anyone help me out?
Regards,
Jesse
--- GENERAL_DB class ----
--- Separate function to create instance of GENERAL_DB ----
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();
}