im creating a webapplication which connects to a database and uses a ODBC connector im using the following code to do this
private void SetupConnection()
{
conn.ConnectionString =
ConfigurationManager.ConnectionStrings["live"].ConnectionString;
OdbcDataAdapter da =
new OdbcDataAdapter("SELECT * FROM MTD_FIGURE_VIEW1 '", conn);
da.Fill(ds);
}
i want to create a try catch statement which will keep on trying to connect to the database.
psudocode will be try above function, if cant connect try again if it does connect without any errors carry on.
can someone please help me on this
Question relevant update from the comments:
i just want it to keep on trying the
reason for this is the web application
im making will never switch of its
constantly refreshing data, but the
database is switched of fro two hours
every night for backup during this
period i want the app to keep on
trying to connect
Note as people have commented, this is really not a good idea. You need some way to distinguish between an “expected” exception where the database is turned off and you want to keep retrying, and the case that something unexpected has happened and you don’t want to keep trying.