i have a table in sqlite database UserSetting
CREATE TABLE "UserSetting" (
"id" INTEGER NOT NULL UNIQUE,
"install" Boolean NOT NULL DEFAULT 0,
"databasetype" TEXT,
"connectionstring" TEXT,
PRIMARY KEY("id" AUTOINCREMENT)
);
this Code for return True or false from first record Usersetting.install where id=1
Function installcomplete() As Boolean
Try
Using con As New SQLiteConnection(GetSQLiteConnectionString(False))
con.Open()
Dim cmd As New SQLiteCommand
With cmd
.CommandText = "Select install from UserSetting where id=1;"
.Connection = con
.CommandTimeout = 10
End With
Dim b As Boolean = CBool(cmd.ExecuteScalar)
con.Close()
Return b
End Using
Catch ex As Exception
MsgBox(ex.Message)
Return False
End Try
End Function
This Method for first record Usersetting.install where id=1
Sub completeinstall(ByVal t As Boolean)
Try
Using con As New SQLiteConnection(GetSQLiteConnectionString(False))
con.Open()
Dim cmd As New SQLiteCommand
With cmd
.CommandText = "Update UserSetting set install =1 where id=1;"
.Connection = con
.CommandTimeout = 10
.ExecuteNonQuery()
End With
con.Close()
End Using
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
When run function installcompleted return real information. but when run completeinstall return error "Database is locked" and i always use "Using" when connection because it dispose connection automatically .how to fix?
GetSqlconnectionstring for build connectionstring from Structure
Public Structure Msql
Shared datasource As String
Shared IntSec As Boolean
Shared username As String
Shared password As String
Shared DatabaseName As String
End Structure
Public Function GetSQLConnectionString(ByVal includeDatabase As Boolean) As String
Dim builder As New SqlConnectionStringBuilder()
'Build a connection string from the user input.'
builder.DataSource = Msql.datasource
builder.IntegratedSecurity = Msql.IntSec
If builder.IntegratedSecurity = False Then
builder.UserID = Msql.username
builder.Password = Msql.password
End If
If includeDatabase Then
builder.InitialCatalog = Msql.DatabaseName
End If
Return builder.ConnectionString
End Function