Link to home
Start Free TrialLog in
Avatar of cycledude
cycledudeFlag for United Kingdom of Great Britain and Northern Ireland

asked on

c# catch exception with access database

Hi

I am working on a winforms c# 2010 application connecting to an MS ACCESS database.

occasionally, users are saying that they are having the same error 'could not update; currently locked'

so what I would like to do is catch this when it arises, wait a few seconds, then loop to try again until the database is updated.

how can I achieve this?

here is a snippet of the code to insert data:

 foreach (string f in fields)
            {
                myFields += f + ", ";
                myValues += "?,";

            }


 OleDbCommand cmd = new System.Data.OleDb.OleDbCommand("INSERT INTO " + table + " (" + myFields + ") Values (" + myValues + ") ", con);

            foreach (string v in values)
            {
                cmd.Parameters.AddWithValue("?", v);
            }

            cmd.CommandType = CommandType.Text;

            try
            {
                cmd.ExecuteNonQuery();
            }
            catch (Exception)
            {

                throw;
            }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cycledude

ASKER

thanks i will try this..

how can I throw the error to test it?
Just comment out the line:
cmd.ExecuteNonQuery();

Open in new window

And replace it with:
thrown new Exception();

Open in new window

thanks

seems to be working ;o)