in

System.Data.SQLite

An open source ADO.NET provider for the SQLite database engine

Database file Locked Error

Last post 11-06-2009 3:57 AM by gireeshkumar. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 11-04-2009 1:30 AM

    Database file Locked Error

     Hi friends , i m developing a mobile application using C#, sqlite3.6 database. i have created CAB file and installed in my Windows Handheld device. I m able to get data from my table which i have inserted using sqlite3 command line utility. but when i logs in using mobile applicatoin and want to do insertion of data i get an error message: Database File is Locked.. but when i want to display data using same form , i get the data in gird view.. What is the problem with insertion operation. My code is bellow:

    my database name is :Stockdb.db

    i have two tables: User_Login(User_Name,Password), Entry_Master(Container_No,Container_name,...... 11 columns).

    When i m using only one table from Stockdb.db i m able to perform all insert operation, display operation, but when i use first User_Login table to verify users,it get verified and my main form is loaded. here i have a command button which loads Entry_Form. this form i enter all the data which is required, when i click on save button i get Database File Locked Error: while when i directly load my main form and and loads my Entry_form i m able to insert data in Entry_table.

    Can't we use two tables one by one from a single database:

    My saving code is as bellow: 

    private void btnok_Click(object sender, EventArgs e)
            {
               // SQLiteTransaction tran1 = null;
                try
                {
                    using (SQLiteConnection con = new SQLiteConnection("Data Source=|DataDirectory|Stockdb.db"))
                    {
                        con.Open();
                        SQLiteCommand cmd2 = new SQLiteCommand();
                        cmd2.Connection = con;
                      //  cmd2.Transaction = tran1;
                        MessageBox.Show("I m in insert process");
                      cmd2.CommandText = "insert into Entry_Table(Container_No,Super_Cd)values('"+txtcontainerno.Text.Trim()+"','"+txtSuperCode.Text.Trim()+"')";
                        cmd2.ExecuteNonQuery();
                        MessageBox.Show("equeted");
                        cmd2.Dispose();
                        MessageBox.Show("Record Inserted");
                      //  tran1.Commit();
                        con.Close();
                    }
                }
                catch (SQLiteException exp)
                {
                    MessageBox.Show(exp.ToString());
                }
            }

    Can any buddy suggest me what is the problem with my code:

  • 11-04-2009 7:40 AM In reply to

    Re: Database file Locked Error

    The problem isn't in your insert code, it's elsewhere, probably when you read the database, that is holding a datareader or some other database object open and not disposing of it, which is leaving the database open in read mode and preventing you from writing.

     

  • 11-05-2009 1:05 AM In reply to

    Re: Database file Locked Error

     hi robert , see my code is bellow: Frist i want to display data from table to grid. than i want to insert data table. 

     private void btnshow_Click(object sender, EventArgs e)
            {
                try
                {
                    using(SQLiteConnection con= new SQLiteConnection("Data Source=|DataDirectory|Logindb.db;"))
                        {
                            con.Open();
                            Grid2.Refresh();
                            SQLiteCommand cmd = new SQLiteCommand();
                            cmd.Connection = con;
                            cmd.CommandType = CommandType.Text;
                            cmd.CommandText = "select * from User_Login";
                            SQLiteDataAdapter da = new SQLiteDataAdapter(cmd);
                            DataSet ds1 = new DataSet();
                            da.Fill(ds1);
                            Grid2.DataSource = ds1.Tables[0];
                            cmd.Dispose();
                            ds1.Dispose();
                            da.Dispose();
                            con.Close();
                        }
                }
                catch (SQLiteException exp)
                {
                    MessageBox.Show(exp.ToString());
                }
            }
    to insert data:

     private void btncreate_Click(object sender, EventArgs e)
            {
                try
                {
                    if (txtUserName.Text != "" && txtPassword.Text != "")
                    {
                        using (SQLiteConnection  con = new SQLiteConnection("Data Source=|DataDirectory|Logindb.db;"))
                        {
                            con.Open();
                            SQLiteCommand cmd1 = new SQLiteCommand();
                            cmd1.Connection = con;
                            cmd1.CommandType = CommandType.Text;
                            cmd1.CommandText = "insert into User_Login(User_Name,Password)values('" + txtUserName.Text.Trim() + "','" + txtPassword.Text.Trim() + "')";
                            cmd1.ExecuteNonQuery();
                            MessageBox.Show("User Created");
                            cmd1.Dispose();
                            con.Close();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Please Fill All Data");
                    }
                }
                catch (SQLiteException exp)
                { MessageBox.Show(exp.ToString()); }
            }

     U can see i have closed all the things in first select operation and in the next command insert i m still closing all the datareader ...

    what mistak i have done here..

    Thanks for ur quick reply.. 

  • 11-05-2009 8:50 AM In reply to

    Re: Database file Locked Error

    I don't see anything obvious.  Can you send me a test application that I can run?

    robert at blackcastlesoft dot com

    Post here when you've sent it so I can be on the lookout for it.

     

  • 11-05-2009 9:15 PM In reply to

    Re: Database file Locked Error

     hi Robert i have sent u mail... pelase check it out..

    Thanks a lot  

  • 11-06-2009 3:57 AM In reply to

    Re: Database file Locked Error

     HI Robort Thansk for help.. actually i have made misktak in code.. when i do login in create a new form Main_form if user is a valid db user. here i have forgotton to close the database .. my Logindb file is still open here.. now i have clsed my db file and all readers before loading another form. One question i want to ask you.the db file i create using SQLite is .db formate and i want export/convert it to .dbf file.. do u have any idea.. actually my client need to import it to Fox Pro 9.0 which need file in .dbf format..

    Thank a lot for ur quick reply..  

Page 1 of 1 (6 items)
Powered by Community Server (Commercial Edition), by Telligent Systems