开发者

Try/Catch in MSI Installer Script

开发者 https://www.devze.com 2023-03-04 11:26 出处:网络
I have a Windows Installer prompting a user for MySQL information (server, port, username, password) and would like to make sure the parameters are correct prior to completing the setup.

I have a Windows Installer prompting a user for MySQL information (server, port, username, password) and would like to make sure the parameters are correct prior to completing the setup.

I have have an Installer project with Custom Actions linked to the Installer Class and am doing my error checking there in the "Install" method. My error occurs at the catch() portion.

Any suggestions or comments greatly appreciated.

Edit: When I hit [Next] the installer installs the application and then prompts the MessageBox (if there's an error) but completes the installation. I was hoping for it to Rollback and bring up the previous screen.

Edit2: The exception caught from MySqlException is: "Unable to connect any of the specified MySQL hosts," which is correct, but the installer doe开发者_Go百科s not return/roll back.

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();
}


To force a rollback of your current installation you can rethrow the exception. you did just display in your messagebox.

0

精彩评论

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

关注公众号