none
Uninstalling a SQL instance programmatically RRS feed

  • Question

  • Hi,

    Currently we deploy SQL Server Express as a part of our installation, and we create our own instance by setting up appropriate parameters.

    ie. SQLEXPR.EXE /qb ADDLOCAL=ALL INSTANCENAME="MyInstance"

    Can anyone please give some advice as to how we would uninstall this instance when the user uninstalls our application.

    The following link explains how to do it via the Add/Remove Programs:
    http://msdn2.microsoft.com/en-us/library/ms143412.aspx

    And the following link explains how to do it manually:
    http://support.microsoft.com/default.aspx?scid=kb;en-us;290991&sd=tech

    But we'd like to remove it programmatically when the user uninstalls our application.

    Any help and advice will be really appreciated.

    Thanks
    Sam
    Monday, November 14, 2005 7:32 AM

Answers

  • Hi Sam,

    Calling MsiExec.exe directly should work, as this is what setup.exe is going to do behind the scenes. I just tested this on my machine and it looks like after I uninstalled the instance with the name MyInstance all the other instances were left in place, along with the tools. The only care that needs to be taken is identifying which Product ID to use. I manually looked up the Product ID for my instance by searching the registry under: HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall until I found a key value with the DisplayName of "Microsoft SQL Server 2005 Express Edition (MYINSTANCE)".

    Jeff.
    Tuesday, November 15, 2005 4:48 PM

All replies

  • Hi Sam, are you asking for the uninstall command line?  If so, it would be very similar to the install command, except you'd now use the REMOVE flag instead of ADDLOCAL.  The command line would be:

    setup.exe /qb REMOVE=ALL INSTANCENAME="MyInstance"

    Depending on how your application is removed and what technology it uses, you could make a call to this command line once your application is removed to uninstall the SQL Server Express instance.

    Thanks,
    Samuel Lester (MSFT)

    Monday, November 14, 2005 8:59 PM
    Moderator
  • Really appreciated that advice.

    At the point of uninstallation I don't actually have access to the SQLEXPR.EXE anymore. So I've been trying the idea of getting the uninstallation event to call a command line, with the following command:

    MsiExec.exe /x {Guid of Microsoft SQL Server Engine} REMOVE=ALL INSTANCENAME="MyInstance" /qb-!

    It appears to do what I'm looking for.

    However, I'm concerned that this may not be the safest thing to do. Would you expect that other existing instances and even future instances to function normally after executing such a command?

    Thanks
    Sam

    Tuesday, November 15, 2005 7:40 AM
  • Hi Sam,

    Calling MsiExec.exe directly should work, as this is what setup.exe is going to do behind the scenes. I just tested this on my machine and it looks like after I uninstalled the instance with the name MyInstance all the other instances were left in place, along with the tools. The only care that needs to be taken is identifying which Product ID to use. I manually looked up the Product ID for my instance by searching the registry under: HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall until I found a key value with the DisplayName of "Microsoft SQL Server 2005 Express Edition (MYINSTANCE)".

    Jeff.
    Tuesday, November 15, 2005 4:48 PM