我有一个Windows安装程序提示用户inputMySQL信息(服务器,端口,用户名,密码),并希望在完成安装之前确保参数是正确的。
我有一个安装程序项目与自定义操作链接到安装程序类,我做我的错误检查在“安装”方法。 我的错误发生在catch()
部分。
任何build议或意见不胜感激。
编辑:当我点击[下一步]安装程序安装应用程序,然后提示MessageBox(如果有错误),但完成安装。 我希望它回滚,并提出以前的屏幕。
编辑2:从MySqlException得到的exception是:“无法连接任何指定的MySQL主机”,这是正确的,但安装程序不会返回/回滚。
public override void Install(IDictionary stateSaver) { base.Install(stateSaver); // parameters from installer // generate connection string conStr MySqlConnection conn = new MySqlConnection(conStr); MySqlCommand cmd = new MySqlCommand(); // open connection and create database try { conn.Open(); cmd.Connection = conn; // create database // create table // insert values to test } catch (MySqlException ex) { //I would like this to go back to the prior page //where it asks for user input MessageBox.Show("There was a problem connecting to the database."); this.Rollback(stateSaver); // not working? } // close connection conn.Close(); }
要强制回滚当前的安装,可以重新抛出异常。 你只是显示在你的消息框。