mardi 3 février 2015

Unable to access SQLite Database form windows services

I have developed an ADD-in for outlook 2010. on outlook startup, ADD-in stored all the mail subjects in SQLite database.


Now i have to create a windows services that will also access same database, and post it on rest-based services. But I am getting an error.


Windows services is not able to access that database.



static void Main()
{
//try
//{
//=======Connection string=============
string dbfile = @"D:\testdatabase.db";

sql_con = new SQLiteConnection
("Data Source= " + dbfile + ";Version=3;New=False;Compress=True;");
//=======Open Connection=============
sql_con.Open();
//=======Create dataset and store value in dataset===================
sql_cmd = sql_con.CreateCommand();
string CommandText = "select * from mailbackup";
DB = new SQLiteDataAdapter(CommandText, sql_con);
//DS.Reset();
DB.Fill(DS);
//=======Store dataset value in text file============
StringBuilder str = new StringBuilder();
int rows = DS.Tables[0].Rows.Count;
for (int i = 0; i < rows;i++ )
{
str.AppendLine(DS.Tables[0].Rows[i].ItemArray[0].ToString());
str.AppendLine(DS.Tables[0].Rows[i].ItemArray[1].ToString());
str.AppendLine(DS.Tables[0].Rows[i].ItemArray[2].ToString());
str.AppendLine(DS.Tables[0].Rows[i].ItemArray[3].ToString());
str.AppendLine(DS.Tables[0].Rows[i].ItemArray[4].ToString());
str.AppendLine(DS.Tables[0].Rows[i].ItemArray[5].ToString());
str.AppendLine(DS.Tables[0].Rows[i].ItemArray[6].ToString());
str.AppendLine(DS.Tables[0].Rows[i].ItemArray[7].ToString());
str.AppendLine(DS.Tables[0].Rows[i].ItemArray[8].ToString());
StreamWriter sw = null;
sw = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "\\LogFile.txt", true);
sw.WriteLine(DateTime.Now.ToString() + ": " + str.ToString());
sw.Flush();
sw.Close();
}
//=======Close Connection=============
sql_con.Close();
//storedata();
//}
//catch(System.Exception ex)
//{

//}
}


I am getting an error



An unhandled exception of type 'Finisar.SQLite.SQLiteException' occurred in SQLite.NET.dll


Additional information: unsupported file format



it is working fine when we change the connection string



sql_con = new SQLiteConnection
("Data Source= " + dbfile + ";Version=3;New=True;Compress=True;");


Create new database and open connection but after creating table using sqlite browser or SQLiteStudio, It start throwing the same error.


Aucun commentaire:

Enregistrer un commentaire