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";
}
}