I've got a form that creates a new user to be added to my database
Before the user is added, a check is made to make sure the username doesn't already exist
Dim sqlConn As New SQLiteConnection("Data Source=" & dbPath & ";Version=3;New=True;Compress=True;Password=mypassword")
sqlConn.Open()
Dim sqlCommand As New SQLiteCommand("SELECT * FROM usertable WHERE username ='" & txtUserName.Text & "'", sqlConn)
Dim sqlReader As SQLiteDataReader = sqlCommand.ExecuteReader()
If sqlReader.HasRows = False Then
sqlReader.Close()
sqlCommand.Dispose()
Dim sInsertSQL As String = "MY INSERT SQL"
sqlCommand = New SQLiteCommand(sInsertSQL, sqlConn)
sqlCommand.ExecuteNonQuery() 'I GET DATABASE IS LOCKED ERROR HERE'
sqlCommand.Dispose()
sqlConn.Close()
ELSE
'Username already exists message box
END IF
I checked out this page before asking my question: Diagnosing cause of SQLite locking
As you can see, I'm closing the Reader and Command before re-querying the database but I still get the locked error. I've even tried closing the connection and reestablishing everything but the error appears at the same line