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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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?
ASKER
Never received a response to my follow-up request.