开发者

Show custom message at the time of deploying a C# windows application

at the time of 开发者_运维知识库deploying the C# windows project i want to catch the exception and show my message if the connection string is not in correct format.


Use the Application.SetUnhandledExceptionMode method to respond to unhandled exceptions.

It is often not feasible to catch all of the exceptions thrown by Windows Forms. Using this method, you can instruct your application whether it should catch all unhandled exceptions thrown by Windows Forms components and continue operating, or whether it should expose them to the user and halt execution.

See the MSDN doc for an example.


What do you mean by 'deploying the C# windows project'? Are you trying to create an installer for the project?

If your connection string for a database connection then you could include the statement block containing the Open method in a try..catch block. Then show a message in case an exception is encountered. Connect will throw an exception if the connection string is in the incorrect format.

using (var connection = new SqlConnection("Persist Security Info=False;Integrated Security=true;server=(local);Initial Catalog=test;"))
{
    try
    {
         connection.Open();
    }
    catch (SqlException sqlException)
    {
        MessageBox.Show(sqlException.Message, "Unable to connect");
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜