Click here to Skip to main content
15,886,758 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi
I am trying to insert a record into a table but getting database locked error in sqlite. I am writing my code in vb.net 2010 and using sqlite3.0 as database.
VB
If Conn.State = ConnectionState.Open Then Conn.Close()
            Conn.Open()
            q1Var = "insert into mstrs(Code,Name,Vil,Adrs,Pin,type,stts) values(" & ID & ",'" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','d',1)"
            Dim cmd1 As New SQLiteCommand(q1Var, Conn)
            cmd1.ExecuteNonQuery()
            If Conn.State = ConnectionState.Open Then Conn.Close()


Thanks in advance
Santosh Sharma
Posted

1 solution

Sorry to all...

sqlite needs the Datareader also to be closed before trying to use the connection for other task.

I had used the connection for a select query in which I closed connection without closing reader.

the below code modification (Marked in Bold and Underlined) solved my problem

VB
If Conn.State = ConnectionState.Open Then Conn.Close()
       Conn.Open()
       Dim ID As Integer = 0
       Dim cmdDis As New SQLiteCommand("select coalesce(Max(Code),0) from mstrs where type='d'", Conn)
       Dim Display As SQLiteDataReader = cmdDis.ExecuteReader()
       If Display.HasRows Then
           //do the stuff here......
       End If
       cmdDis.Dispose()
       Display.Close()
       If Conn.State = ConnectionState.Open Then Conn.Close()
   End Sub


Regards
Santosh Sharma
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900