Ошибка sql logic error or missing database

I am trying to read all data from the table Condition in a local sqlite database. However I am getting this error:

SQL logic error or missing database no such table

The database is located in the same directory as the file that’s calling it.

This is my code:

SQLiteConnection m_dbConnection = new SQLiteConnection("Data Source=myDatabase.sqlite;Version=3;");
m_dbConnection.Open();

try
{
    string sql = "select * from Condition";
    SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);

    SQLiteDataReader reader = command.ExecuteReader();

    while (reader.Read())
        Console.WriteLine("Name: " + reader["name"] + "tScore: " + reader["id"]);

    Console.ReadLine();
    return null;
}
catch (Exception exc)
{
    return null;
}
finally
{
    m_dbConnection.Close();
}

Willi Mentzel's user avatar

Willi Mentzel

27.4k20 gold badges112 silver badges119 bronze badges

asked Mar 25, 2015 at 8:07

Jetpack's user avatar

2

The database should be located in your bin folder, or else specify the absolute path to the .sqlite file.

answered Mar 25, 2015 at 8:20

Cristina Alboni's user avatar

0

I received the same error message on a linux system. When the database was created, the program was running as root: when the error occurred, the program was running as me. Basically, I didn’t have write permission on the file.

answered Mar 12, 2021 at 12:36

JavaLatte's user avatar

JavaLatteJavaLatte

3665 silver badges18 bronze badges

Студворк — интернет-сервис помощи студентам

Всем привет!
Хочу записать данные в SQLite, а она ругается:

SQL logic error or missing database
near «integer»: syntax error

Не пойму в чем дело.
Проверил запрос. Вроде все правильно:

SQL
1
"INSERT INTO 'Folds' (id INTEGER, name TEXT, type INTEGER) VALUES ( 0, 'НОВЫЙ ТОВАР', 0);"

Сам код такой:

C#
1
2
3
4
5
6
7
8
9
10
11
12
                comFoldLines += "( " + i.ToString() + ", '";
                comFoldLines += fs[i].Name + "', ";
                comFoldLines += Convert.ToInt32(fs[i].OC) + ")";
                //if (i != fs.Count - 1) comFoldLines += ",";
 
                SQLiteCommand commandInFold = new SQLiteCommand("INSERT INTO 'Folds' (" +
                        "id INTEGER, " +
                        "name TEXT, " +
                        "type INTEGER)" +
                    " VALUES " + comFoldLines + ";", connection);
 
                commandInFold.ExecuteNonQuery();

Таблица создавалась так:

C#
1
2
3
4
5
6
7
8
9
10
11
            SQLiteCommand commandCreFold = new SQLiteCommand("CREATE TABLE Folds (" +
                    "id INTEGER PRIMARY KEY, " +
                    "name TEXT, " +
                    "type INTEGER" +
                    ");", connection);
 
            string comFoldLines = string.Empty;
 
            connection.Open();
 
            commandCreFold.ExecuteNonQuery();   //создана таблица:

С моей точкт зрения синтаксис правильный. С MySQL работал так много раз. Смотрел на документацию SQLite, вроде синтаксис такой же.
В чем может быть ошибка?

  • Remove From My Forums
  • Question

  •     

                SQLiteCommand command = new SQLiteCommand(connection);
                command.CommandText = "UPDATE glasba SET Naslov ='" + textBox1.Text+"', Izvajalec = '"+textBox2.Text+"', Zanr ='"+textBox3.Text+"', Ocena ='"+textBox4.Text+"') WHERE (Naslov = '" + imes + "') AND (Izvajalec = '" + imea + "') ";
                connection.Open();
                command.ExecuteNonQuery();
                connection.Close();
                this.Hide();

    System.Data.SQLite.SQLiteException
      HResult=0x80004005
      Message=SQL logic error or missing database
    near «=»: syntax error

    I dont know what to do, this error getting up even though i tried adding parameters and so on…

Answers

  • Hi

    Thank you for posting here.

    According to your description, you want to solve the error that ’ System.Data.SQLite.SQLiteException’.

    You could try the following code.

                SQLiteConnection connection = new SQLiteConnection(@"Data Source = MyDatabase.sqlite");
                connection.Open();
                string sql = String.Format("UPDATE glasba SET naslov ='{0}', izvajalec='{1}',zanr='{2}',ocena='{3}' ,review='{4}' WHERE naslov = 'test1' and izvajalec='test2'",textBox1.Text,textBox2.Text,textBox3.Text,textBox4.Text,textBox5.Text);
                SQLiteCommand command = new SQLiteCommand(sql,connection);
                command.ExecuteNonQuery();
                connection.Close();
    
    

    Result:

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click «Mark as Answer» the responses that resolved your issue, and to click «Unmark as Answer» if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to
    MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by

      Tuesday, March 26, 2019 5:14 PM

    • Unproposed as answer by
      Cherkaoui.Mouad
      Tuesday, March 26, 2019 5:15 PM
    • Marked as answer by
      Twinkiiee
      Wednesday, April 3, 2019 2:43 PM

FreePBX Community Forums

Loading

Asterisk Community

Loading

Понравилась статья? Поделить с друзьями:
  • Ошибка sql 2006 mysql server has gone away
  • Ошибка spn 158 fmi 2
  • Ошибка sql error code 206
  • Ошибка sql 1366 incorrect string value
  • Ошибка spn 1382 fmi 1 камаз евро 5