Search code examples
c#databaseproduction-environment

C#: How to graciously manage errors on the application DataBase?


I have a C# application that uses a localhost DB (MySQL).

Now, when I create the executable I´m assuming that the receptor computer MUST have the exact DB with the the same name and tables, also, must have running WAMP or XAMPP.

If one of this conditions is not accomplished the program will crash horribly, with the errors of Windows/C#.

I could put exceptions for every case, but I´m fearful that I would hide other errors putting exceptions for everything!

With production software, how do you manage this? With exceptions? Writing a manual for the user? etc?


Solution

  • During bootstrapping, I recommend check to see if a DB Connection can be created (in my case, SQL Server), given the database connection string defined in an app.config. Initially, you should do some version checking on the database. If the database can't be found, attempt to create it. if i'ts out of date, attempt to upgrade it. If this process fails, then your database engine instance isn't installed or is unresponsive. For my application case, I exit the program, as there's nothing else to do if the DB can't be accessed.

    Once past this point, I generally assume that the DB connection is active.