When I insert data into a SQLite table, it says that the database is blocked

0

I am creating an application in WPF which inserts in a table of SQLite every login.

When you are about to insert: throw this exception:

The code of the method to insert is this:

public void InsertValuesToDataBase (string user, string pass)
    {
        if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "DB.sqlite"))
        {
            SQLiteConnection conectionInsert = new SQLiteConnection("Data Source=" + AppDomain.CurrentDomain.BaseDirectory + "DB.sqlite;" + "Version=3;");

            string consulta = "INSERT INTO User (user, pass) values(@param1,@param2)";

            SQLiteCommand Insert = new SQLiteCommand(consulta, conectionInsert);

            Insert.Parameters.AddWithValue("@param1", user);
            Insert.Parameters.AddWithValue("@param2", pass);

            conectionInsert.Open();
            Insert.ExecuteNonQuery();
            conectionInsert.Close();
        }
        else
        {
            //alter here
        }
    }

And I call him from another class in this way:

sim_sql_lite = new SIMSQLite();
sim_sql_lite.InsertValuesToDataBase("abc", "123");

The location of the SQLite file is in the same directory where Visual Studio creates the compiled .exe of the program.

C:\...\bin\Debug

Any suggestions?

    
asked by JGuerra 04.04.2018 в 18:04
source

2 answers

2

Maybe the manager of Sqlite Open Helper has been stuck, once I happened that this manager had been stuck and I had blocked the database. Try restarting the manager. Greetings

    
answered by 04.04.2018 / 18:50
source
0

The Password field appears to be missing in the connection string.

public void InsertValuesToDataBase (string user, string pass)
{
    if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "DB.sqlite"))
    {
        SQLiteConnection conectionInsert = new SQLiteConnection("Data Source=" + AppDomain.CurrentDomain.BaseDirectory + "DB.sqlite;" + "Version=3; Password=012345679;");

        string consulta = "INSERT INTO User (user, pass) values(@param1,@param2)";

        SQLiteCommand Insert = new SQLiteCommand(consulta, conectionInsert);

        Insert.Parameters.AddWithValue("@param1", user);
        Insert.Parameters.AddWithValue("@param2", pass);

        conectionInsert.Open();
        Insert.ExecuteNonQuery();
        conectionInsert.Close();
    }
    else
    {
        //alter here
    }
}
    
answered by 04.04.2018 в 18:52