cycledude
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:
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;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Just comment out the line:
cmd.ExecuteNonQuery();
And replace it with:thrown new Exception();
ASKER
thanks
seems to be working ;o)
seems to be working ;o)
ASKER
how can I throw the error to test it?