System.Data.SqLite not working on release mode in visual studio 2017 community edition

905 views Asked by At

I'm developing a windows service which uses System.Data.SQLite (NuGet Package). In Debug mode service is running well but in release mode, after installing the service on windows 10 it didn't work. Here is a snapshot of the error when i tried to start the service

enter image description here

I'm using Visual Studio 2017 Community edition on windows 10 and developing service on .NET 4 framework. I got these from the FAQ at https://system.data.sqlite.org/index.html/doc/trunk/www/faq.wiki#q3. But I'm not sure that I'm this having trouble because of the community edition of visual studio.

Currently, Visual Studio 2005, 2008, 2010, 2012, 2013, and 2015 are supported, including the "Express" editions; however, in order to build the entire solution, including the necessary native code, the "Professional" edition (or higher) is required.

Here is my SQLite Manager class

using System;
using System.Collections.Generic;
using System.Data.SQLite;
using System.IO;

namespace JST3X
{
    public class SQLiteDBManager
    {
        private string dbFullPath;
        private string DBConnectionString;
        private string DBPassword;
        private SQLiteConnection DBConnction;

        public SQLiteDBManager(string FullFilePath, string Password = null, Boolean CreateIfNotExist = false)
        {
            this.dbFullPath = FullFilePath;
            if ((!File.Exists(this.dbFullPath)) && CreateIfNotExist)
            {
                SQLiteConnection.CreateFile(this.dbFullPath);
            }
            else if (!File.Exists(this.dbFullPath))
            {
                Console.WriteLine(this.dbFullPath + " not found!");
                return;
            }

            if (Password != null)
            {
                this.DBPassword = Password;
                this.DBConnectionString = "Data source=" + this.dbFullPath + ";Password=" + this.DBPassword;
                this.DBConnction = new SQLiteConnection(this.DBConnectionString);
                this.DBConnction.SetPassword(this.DBPassword);
            }
            else
            {
                this.DBConnectionString = "Data source=" + this.dbFullPath;
                this.DBConnction = new SQLiteConnection(this.DBConnectionString);
            }
        }
    }
}

EDIT:

I was trying to access the SQLite database through windows service program and the database was created using windows form application. The WFA was accessing the directory C:\Users\<user>\AppData\Local to store files while service application was accessing directory C:\Windows\SysWOW64\config\systemprofile\AppData\Local to look for files.

I solved (somehow fixed) the problem by storing the directory in environment variables so that both programs will use the same absolute directory. One can post the elegant way of solving this problem.

0

There are 0 answers