Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8576591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:57:32+00:00 2026-06-11T19:57:32+00:00

I have a trouble with the following code. The program seems to stuck sometimes

  • 0

I have a trouble with the following code. The program seems to stuck sometimes (apparently no pattern…often in the second query since the form containing this code run but not always) for 5-20 seconds in the row

Dim rdr As SQLiteDataReader = cmd.ExecuteReader

If the code doesn’t stuck in second query since form started, it won’t never stuck. If I close and reopen the form I have the same 50-60% chance to have same error mostly on 2nd query.

Then it always restart from this point sometimes with no error…just big delay of 5-20 seconds and sometimes with error “The database file is locked, database is locked” at line

cmd.ExecuteNonQuery()
(2° time..not inside if block)

This error will forbid the user to save its change and sometimes corrupt the data record and, of course, introduces a huge delay that I can’t accept 🙁

Any Idea of what I’m doing wrong?

I’m developing with visual studio 2008 for a windows CE 6.0 device with 3.5 framework and

ADO.NET 2.0/3.5 SQLite Data Provider
Version 1.0.66.0 April 18, 2010
Using SQLite 3.6.23.1
http://sqlite.phxsoftware.com/

Thank you

'Update current program on database
Public Sub AggiornaUserOnDatabase(ByVal name As String, ByVal password As String, ByVal permission As String)
    'No spaces
    name = Trim(name)
    'Database var
    Dim ConString As String = "Data Source = " + DatabaseAccountPath + ";"
    Dim con As New SQLiteConnection
    Dim cmd As SQLiteCommand
    'Read from database
    Try
        con.ConnectionString = ConString
        con.Open()
        'Check if row is existing
        cmd = con.CreateCommand
        cmd.CommandText = "SELECT " + DBACCNAME + " FROM " + DatabaseAccountTableName + " WHERE " + DBACCNAME + " = '" + name + "'"
        Dim rdr As SQLiteDataReader = cmd.ExecuteReader
        'If empty...create the record
        If Not rdr.Read Then
            cmd = con.CreateCommand
            cmd.CommandText = "INSERT INTO " + DatabaseAccountTableName + " (" + DBACCNAME + ") VALUES ('" + name + "')"
            cmd.ExecuteNonQuery()
        End If
        rdr.close()
        'Update the values
        cmd = con.CreateCommand
        cmd.CommandText = "UPDATE " + DatabaseAccountTableName + " SET " _
                        + DBACCPASSWORD + " = '" + password + "', " _
                        + DBACCPERMISSION + " = '" + permission + "' " _
                        + "WHERE " + DBACCNAME + " = '" + name + "'"
        cmd.ExecuteNonQuery()
        cmd.Dispose()
        con.Close()
    Catch ex As Exception
        AggiungiRigaSuFile(ErroriPath, "Editing users account database: " + ex.Message, Configurazione.DiagnosticaOff, True)
    End Try
End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T19:57:33+00:00Added an answer on June 11, 2026 at 7:57 pm

    You are using the cmd when it has an open reader. You need to close the reader before you use the cmd again. And don’t even use a reader. Do a select count(*) to to see if the record exists.

    cmd.CommandText = "SELECT count(*) FROM " + ...
    int rowRet = (Int32)sqlCmd2.ExecuteScalar();
    
    if (rowCount == 0)
    {
        // do NOT create the command gain just use it
        cmd.CommandText = "INSERT INTO " + DatabaseAccountTableName ...
        // insert all the values here so the update is not required
        cmd.ExecuteNonQuery();
    }
    else if (rowCount == 1)
    {
        cmd.CommandText = "UPDATE " + DatabaseAccountTableName + " SET " _
                        + DBACCPASSWORD + " = '" + password + "', " _
                        + DBACCPERMISSION + " = '" + permission + "' " _
                        + "WHERE " + DBACCNAME + " = '" + name + "'"
        cmd.ExecuteNonQuery();
    }
    else 
    {
         // throw an error expected 0 or 1
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have trouble to get gluLookAt working. I have the following code which works
I have a question. I have the following program and I'm having trouble with
I have trouble finding a solution for the following problem: I have a lot
I am having trouble with the following SQL statement. I have had this issue
Following this question and answer , I still have a bit trouble in the
Im having trouble with creating a JS bookmarklet, I have the following that when
I have some trouble with some inline assembly code. I know what should be
I have some trouble showing a disabled Form in non-modal state. Here is the
I have the following code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using
I am learning Objective C I have the following trouble. If I use the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.