in

System.Data.SQLite

An open-source, enhanced version of the SQLite database engine for Windows

The type initializer for 'System.Data.SQLite.SQLiteFunction' threw an exception.

Last post 04-20-2008 2:42 PM by rstander. 9 replies.
Page 1 of 1 (10 items)
Sort Posts: Previous Next
  • 04-15-2008 10:44 AM

    The type initializer for 'System.Data.SQLite.SQLiteFunction' threw an exception.

    I'm using Visual Studio 2008 on Windows Vista 32bit. While running on my development machine everything works fine, even while debugging or running exe directly. I did some tests on a brand new Windows XP machine in the office, and get the error in the title.

    Any ideas?

    This is the code that gives the error:

        private bool GetCurrentVersion( out int pVersion, out string pError )
        {
          pError = "";
          pVersion = 0;
          SQLiteConnection con = new SQLiteConnection( clsCMDSLib.ConnectionString );
          try
          {
            con.Open();
            SQLiteCommand sqltables = new SQLiteCommand( " SELECT COUNT( * ) AS counter FROM sqlite_master WHERE type = 'table' AND name = 'version' ", con );
            int tablecounter = Convert.ToInt32( sqltables.ExecuteScalar() );
            if ( tablecounter > 0 )
            {
              SQLiteCommand sqlrows = new SQLiteCommand( " SELECT COUNT( * ) AS counter FROM version ", con );
              int rowcounter = Convert.ToInt32( sqlrows.ExecuteScalar() );
              if ( rowcounter == 0 )
              {
                SQLiteCommand sqlins = new SQLiteCommand( " INSERT INTO version ( version ) VALUES ( 0 ) ", con );
                sqlins.ExecuteNonQuery();
                pVersion = 0;
              }
              else
              {
                SQLiteCommand sqlsel = new SQLiteCommand( " SELECT version FROM version ", con );
                SQLiteDataReader readsel = sqlsel.ExecuteReader();
                if ( readsel.Read() )
                {
                  pVersion = readsel.GetInt32( 0 );
                  return true;
                }
                else
                {
                  pVersion = 0;
                  return false;
                }
              }
            }
            else
            {
              SQLiteCommand sqlcreatetable = new SQLiteCommand( " CREATE TABLE version ( version integer NOT NULL default '0' ) ", con );
              sqlcreatetable.ExecuteNonQuery();
              sqlcreatetable.CommandText = " INSERT INTO version ( version ) VALUES ( 0 ) ";
              sqlcreatetable.ExecuteNonQuery();
              pVersion = 0;
            }
            return true;
          }
          catch ( Exception ex )
          {
            pError = "Error getting/creating version with message: " + ex.Message;
            return false;
          }
          finally
          {
            con.Close();
            con.Dispose();
          }
        }

    These 2 functions generates the connection string:

        public static string ImageStore
        {
          get
          {
            string location = Environment.GetFolderPath( Environment.SpecialFolder.LocalApplicationData ).IncludeTrailingBackslash() + @"LibDat\";
            try
            {
              if ( !Directory.Exists( location ) ) Directory.CreateDirectory( location );
            }
            catch { }
            return location;
          }
        }

        public static string ConnectionString
        {
          get
          {
            return "Data Source=" + ImageStore + "Data.db";
          }
        }
     

  • 04-15-2008 11:11 AM In reply to

    Re: The type initializer for 'System.Data.SQLite.SQLiteFunction' threw an exception.

    Not a clue...I assume this brand new XP machine has .NET 2.0 (and all subsequent 2.0 patches) installed?

     

  • 04-15-2008 12:44 PM In reply to

    Re: The type initializer for 'System.Data.SQLite.SQLiteFunction' threw an exception.

    Yes it does. All windows updates are up to date.
  • 04-15-2008 12:51 PM In reply to

    Re: The type initializer for 'System.Data.SQLite.SQLiteFunction' threw an exception.

    Any way to get a stack dump?

     

  • 04-16-2008 8:10 AM In reply to

    Re: The type initializer for 'System.Data.SQLite.SQLiteFunction' threw an exception.

    This is the stack dump that I get when it thows the exception:

       at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
       at System.Environment.get_StackTrace()
       at Enquire_Application.clsDBVersion.GetCurrentVersion(Int32& pVersion, String& pError)
       at Enquire_Application.clsDBVersion.Run(String& pError)
       at Enquire_Application.Program.Main()

    As I said earlier, it works perfectly fine in VS2008, and also when running the exe directly on my Vista machine. Only when I run the exe on another XP machine do I get the error. I've also tried downgrading to 1.0.35, but with the same problem. 

    What I don't understand is that I have another application in which I do exactly the same, and I don't have this problem.

  • 04-16-2008 8:23 AM In reply to

    Re: The type initializer for 'System.Data.SQLite.SQLiteFunction' threw an exception.

    Weird.  I'll look into surrounding some key pieces of that code with try/catch blocks.  Perhaps there's some permission issue or other issue prventing that code from enumerating the loaded assemblies.

     

  • 04-16-2008 8:47 AM In reply to

    Re: The type initializer for 'System.Data.SQLite.SQLiteFunction' threw an exception.

    Just now I did the following, with exactly the same problem. I made a function that runs the statement below, and it keeps throwing the same exception.

             SQLiteCommand sqldate = new SQLiteCommand( " select date() ", con );
            SQLiteDataReader rdrdate = sqldate.ExecuteReader();
            rdrdate.Read();

    In this case a try/catch block does not mean much, as I cannot run any statement agains sqlite. This happens on any Windows XP computer in our office I've tried, and they are all running under the Administrator accounts.

  • 04-16-2008 8:51 AM In reply to

    Re: The type initializer for 'System.Data.SQLite.SQLiteFunction' threw an exception.

    What I meant was -- I will place try/catch blocks in the static initializer for SQLiteFunction in an attempt to keep it from blowing up.

     

  • 04-16-2008 11:18 AM In reply to

    Re: The type initializer for 'System.Data.SQLite.SQLiteFunction' threw an exception.

    Will this be released in a new version then?

    Just to give you some more info. I don't know if this might be what is causing this, but the project is a .Net 3.5 project using WCF.

    Thanks for all the help and advice so far.

  • 04-20-2008 2:42 PM In reply to

    Re: The type initializer for 'System.Data.SQLite.SQLiteFunction' threw an exception.

    Does anyone have any further ideas about this issue, as I'm currently not able to deploy this project?

    Thanks

Page 1 of 1 (10 items)
Powered by Community Server (Commercial Edition), by Telligent Systems