How to fix the error "No connection associated with this command"?

SQLiteConnection connect = new SQLiteConnection("Data Source=base.db;");
SQLiteCommand command = new SQLiteCommand(@"UPDATE voices SET pass = '" + pass + 
 "', hash = '" + hash + 
 "' WHERE id = '" + id + "'");

Actually not updating records in a table fails with the error "No connection associated with this command" in the 6th line.
In what may be the problem?
June 27th 19 at 14:54
1 answer
June 27th 19 at 14:56
Well, logical. The connection in itself, command itself.

If you just look at the description SqlCommand (architecture for SQLite - the same)

there you can see the following:

using (SqlConnection conn = new SqlConnection(connectionString)) {
 using (SqlCommand cmd = new SqlCommand(commandText, conn)) {
 // There're three command types: StoredProcedure, Text, TableDirect. The TableDirect 
 // type is only for OLE DB. 
 cmd.CommandType = commandType;

 return cmd.ExecuteNonQuery();

The team is constructed with reference to the connection that will be used.

Exactly the same example given in the description of the SQLiteCommand

public void ReadMyData(string myConnString)
 string mySelectQuery = "SELECT DeptNo, DName FROM Dept";
 SQLiteConnection sqConnection = new SQLiteConnection(myConnString);
 SqCommand SQLiteCommand = new SQLiteCommand(mySelectQuery,sqConnection); // command is constructed by specifying connection!!!
 SQLiteDataReader sqReader = sqCommand.ExecuteReader();
 while (sqReader.Read())
 Console.WriteLine(sqReader.GetInt32(0).ToString() + ", " + sqReader.GetString(1));
 // always call Close when done reading.
 // always call Close when done reading.

In General, the answer to the question "how to fix" one is to understand the essence.
Interesting point is that similar queries SELECT and INSERT work fine.
In their image and likeness I created this miracle - karine.Konopelski commented on June 27th 19 at 14:59
: well, miracles do happen -))) - delta89 commented on June 27th 19 at 15:02

Find more questions by tags C#SQLSQLite