Link to home
Start Free TrialLog in
Avatar of dev775
dev775

asked on

Data Connection Failed – Error Handling

When a connection to a data source fails (because the path is wrong or the database is unavailble) I would like to present the user with a friendly error message rather than the “unhandled error” message from Windows.  I am looking for help with some C# code to efficiently handle a connection error and maybe provide a message that identifies the type of error.  Any help is greatly appreciated!
ASKER CERTIFIED SOLUTION
Avatar of Si_Hibbard
Si_Hibbard
Flag of United States of America 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
I would use a try/catch but also use the classes derived from DbException which can then give you more details. For example SqlException has a property Number. The details on these error messages are in master.dbo.sys.messages
Avatar of dev775
dev775

ASKER

Would it be possible to walk through an example?  For instance in my application the user must enter the path to the data files and clicks a button to connect to the database.  If the wrong path is entered and the button event cannot connect to the db, how would I handle this type of event?
Avatar of dev775

ASKER

Never received a response to my follow-up request.