Including a named instance of SQL Server 2008 Express with my application

我们两清 提交于 2019-12-04 10:20:43

We encountered a similar issue to this when we tried to deploy a named instance of SQL 2008 Express R2 with our shrink wrapped app. We did get it working by making a custom bootstrapper. Below are copies of the entries from our wiki that describe this, hopefully they will be of use to others trying to do this.

One important point to note is that in VS2012/2013 we are yet to work out how to make this work with InstallShield LE (ISLE), so if you are adopting this solution now and planning to upgrade VS then this is probably not worth doing, better to find a solution that will work in ISLE too.

SQL 2008 R2 Prerequisite Bootstrapper for use in Setup Projects

Out of the box in VS2010, It is not possible to set SQL2008 Express R2 as a prerequisite for a Setup project. The reason this is not possible is that there is no 'bootstrapper' for R2, only for 2008 Express. Additionally, MS do not plan to add a bootstrapper for R2 as VS simply gets bootstrappers for whatever versions of SQL existed when that version of VS was released (R2 was released after VS2010).

As there is no MS bootstrapper for SQL 2008 R2, you need to create your own as per this article:

http://robindotnet.wordpress.com/2011/02/06/how-about-a-bootstrapper-package-for-sqlserver-express-2008-r2/

This bootstrapper either creates the SQLEXPRESS instance if no older instance with that name exists, or updates an earlier instance with the name SQLEXPRESS to SQL Express 2008 R2.

NB: Changing the name of the SQL instance CANNOT be done with this as it stands, as the sqlversionchk.exe program used by the xml file is programmed to check only the instance called SQLEXPRESS and there is no way to pass it an alternate name. We have solved this issue by creating a new variant of the above files that do not use the sqlversionchk exe, but instead use a reg check to determine if SQL is installed and if so what version:

SQL 2008 R2 Named Instance Bootstrapping

Goal: Use proper VS Setup project boot strapper (i.e. tick that 2008 R2 is a pre-requisite in the setup project pre-reqs) and then have the setup project install or upgrade a custom named instance of SQL Server.

Success: We have created a custom bootstrapper for our app's version of SQL , it does away with the SQLVersionCh.exe program altogether.

What we did:

We started with robindotnet's custom R2 bootstrapper as detailed above.

We then removed all of the references to sqlversionchk.exe and replaced them with registry checks for the what the current version of sql is. This is not as thorough as sqlversionchk, as that will also check things like whether the SQL instance is in the right language and a lot of conditions about if x version of sql is currently installed then it cannot be updated. however, for our purposes this doesn't matter, as we are in control of the instance (as it is a custom instance not the default SQLEXPRESS instance) so we will know what versions it can possibly be and so we can check for these versions.

The bootstrapper then works by simply checking the following four scenarios, of which only one should ever be true (i.e. the four scenarios should be mutually exclusive)

Scenario 1: Platform: x86
Registry check: No registry value for our instance name Action: Nothing in the registry, therefore SQL not installed, if this is an x86 machine install SQL

Scenario 2: Platform: x86
Registry Check: registry value not equal to the most current SQL version we are using
Action: Upgrade our existing custom named instance to the version of SQL we are currently using.

This logic is theoretically wrong if the installed version of SQL was a later version than the one we are trying to install (as we would be upgrading to an earlier version, which would fail), but this should never happen unless the user decides to manually upgrade our instance of SQL, which is beyond our ability to control.

Scenario 3: Platform: amd64 (note this does not mean this is an amd machine, just that it is a 64bit Windows installation)
Registry Check: No registry value for our instance name
Action: Nothing in the registry, therefore SQL not installed, if this is an 64 bit machine install SQL

Scenario 4: Platform: amd64
Registry Check: registry value not equal to the most current SQL version we are using Action: Upgrade our existing custom named instance to the version of SQL we are currently using.

The full bootstrapper file is detailed at the end of this post.

How this custom bootstrapper will change in the future

We can check for whatever version numbers we like in the registry and determine what version is installed. We can then steer the execution as appropriate. For example if you need to have upgraded to 2008 R2 before you can then update to 2010, we can do that using the bypassIf construct and simply introducing more variations into the table above.

Our version of the bootstrapper:

Note that the custom instance name is 'MVXBM'

<?xml version="1.0" encoding="utf-8" ?>

<Package

xmlns="http://schemas.microsoft.com/developer/2004/01/bootstrapper"

Name="DisplayName"

Culture="Culture"

LicenseAgreement="eula.rtf">


  <PackageFiles CopyAllPackageFiles="false">

    <PackageFile Name="SQLEXPR32_x86_ENU.EXE" HomeSite="SqlExpr32Exe"/>

    <PackageFile Name="SQLEXPR_x64_ENU.EXE" HomeSite="SqlExpr64Exe"/>

    <PackageFile Name="eula.rtf"/>

  </PackageFiles>


  <InstallChecks>

<RegistryCheck Property="SQLVersion" Key="HKLM\SOFTWARE\Microsoft\Microsoft SQL Server\MVXBM\MSSQLServer\CurrentVersion" Value="CurrentVersion" />

  </InstallChecks>


  <Commands Reboot="Defer">


    <!-- Defines a new installation (x86) -->

    <Command PackageFile="SQLEXPR32_x86_ENU.EXE"

Arguments='/q /hideconsole /action=Install /features=SQL /instancename=MVXBM /enableranu=1 /sqlsvcaccount="NT Authority\Network Service" /AddCurrentUserAsSqlAdmin /skiprules=RebootRequiredCheck /IAcceptSQLServerLicenseTerms'

EstimatedInstalledBytes="225000000"

EstimatedInstallSeconds="420">

      <InstallConditions>

        <FailIf Property="VersionNT" Compare="ValueNotExists" String="GeneralFailure"/>

        <FailIf Property="VersionNT" Compare="VersionLessThan" Value="5.1.2" String="InvalidPlatformXP"/>

        <FailIf Property="VersionNT" Compare="VersionEqualTo" Value="5.2.0" String="InvalidPlatform2K3"/>

        <FailIf Property="VersionNT" Compare="VersionEqualTo" Value="5.2.1" String="InvalidPlatform2K3"/>

        <FailIf Property="AdminUser" Compare="ValueEqualTo" Value="false" String="AdminRequired"/>

        <BypassIf Property="ProcessorArchitecture" Compare="ValueNotEqualTo" Value="Intel"/>

        <BypassIf Property="SQLVersion" Compare="ValueExists"/>

      </InstallConditions>

      <ExitCodes>

        <ExitCode Value="0" Result="Success"/>

        <ExitCode Value="1641" Result="SuccessReboot"/>

        <ExitCode Value="3010" Result="SuccessReboot"/>

        <!-- 0x84BE0BC2 (1214,3010) -->

        <ExitCode Value="-2067919934" Result="FailReboot"/>

        <!-- 0x84C10BC2 (1217,3010) -->

        <ExitCode Value="-2067723326" Result="FailReboot"/>

        <!-- 0x84BE0007 (1214,7) -->

        <ExitCode Value="-2067922937" Result="Fail" String="AdminRequired"/>

        <!-- 0x84C4001F (1220,31) -->

        <ExitCode Value="-2067529697" Result="Fail" String="AdminRequired"/>

        <!-- 0x84BE0001 (1214,1)-->

        <ExitCode Value="-2067922943" Result="Fail" String="InvalidPlatformOSServicePacks"/>

        <!-- 0x84C4000B (1220,11) -->

        <ExitCode Value="-2067529717" Result="Fail" String="AnotherInstanceRunning"/>

        <!-- 0x84BE01F8 (1214,504) -->

        <ExitCode Value="-2067922440" Result="Fail" String="BetaComponentsFailure"/>

        <!-- 0x84BE01FA (1214,506) -->

        <ExitCode Value="-2067922438" Result="Fail" String="BetaComponentsFailure"/>

        <!-- 0x84BE0202 (1214,514) -->

        <ExitCode Value="-2067922430" Result="Fail" String="InvalidPlatformArchitecture"/>

        <!-- 0x84BE0203 (1214,515) -->

        <ExitCode Value="-2067922429" Result="Fail" String="InvalidPlatformArchitecture"/>

        <ExitCode Value="216" Result="Fail" String="InvalidPlatformArchitecture"/>

        <DefaultExitCode Result="Fail" FormatMessageFromSystem="true" String="GeneralFailure" />

      </ExitCodes>

    </Command>


    <!-- Defines an upgrade installation (x86) -->

    <Command PackageFile="SQLEXPR32_x86_ENU.EXE"

Arguments="/q /hideconsole /action=Upgrade /instancename=MVXBM /skiprules=RebootRequiredCheck /IAcceptSQLServerLicenseTerms"

EstimatedInstalledBytes="225000000"

EstimatedInstallSeconds="420">

      <InstallConditions>

        <BypassIf Property="ProcessorArchitecture" Compare="ValueNotEqualTo" Value="Intel"/>

        <BypassIf Property="SQLVersion" Compare="ValueNotExists"/>

        <BypassIf Property="SQLVersion" Compare="ValueEqualTo" Value="10.50.1600.1"/>

      </InstallConditions>

      <ExitCodes>

        <ExitCode Value="0" Result="Success"/>

        <ExitCode Value="1641" Result="SuccessReboot"/>

        <ExitCode Value="3010" Result="SuccessReboot"/>

        <!-- 0x84BE0BC2 (1214,3010) -->

        <ExitCode Value="-2067919934" Result="FailReboot"/>

        <!-- 0x84C10BC2 (1217,3010) -->

        <ExitCode Value="-2067723326" Result="FailReboot"/>

        <!-- 0x84BE0007 (1214,7) -->

        <ExitCode Value="-2067922937" Result="Fail" String="AdminRequired"/>

        <!-- 0x84C4001F (1220,31) -->

        <ExitCode Value="-2067529697" Result="Fail" String="AdminRequired"/>

        <!-- 0x84BE0001 (1214,1)-->

        <ExitCode Value="-2067922943" Result="Fail" String="InvalidPlatformOSServicePacks"/>

        <!-- 0x84C4000B (1220,11) -->

        <ExitCode Value="-2067529717" Result="Fail" String="AnotherInstanceRunning"/>

        <!-- 0x84BE01F8 (1214,504) -->

        <ExitCode Value="-2067922440" Result="Fail" String="BetaComponentsFailure"/>

        <!-- 0x84BE01FA (1214,506) -->

        <ExitCode Value="-2067922438" Result="Fail" String="BetaComponentsFailure"/>

        <!-- 0x84BE0202 (1214,514) -->

        <ExitCode Value="-2067922430" Result="Fail" String="InvalidPlatformArchitecture"/>

        <!-- 0x84BE0203 (1214,515) -->

        <ExitCode Value="-2067922429" Result="Fail" String="InvalidPlatformArchitecture"/>

        <ExitCode Value="216" Result="Fail" String="InvalidPlatformArchitecture"/>

        <DefaultExitCode Result="Fail" FormatMessageFromSystem="true" String="GeneralFailure" />

      </ExitCodes>

    </Command>


    <!-- Defines a new installation (amd64) -->

    <Command PackageFile="SQLEXPR_x64_ENU.EXE"

Arguments='/q /hideconsole /action=Install /features=SQL /instancename=MVXBM /enableranu=1 /sqlsvcaccount="NT Authority\Network Service" /AddCurrentUserAsSqlAdmin /skiprules=RebootRequiredCheck /IAcceptSQLServerLicenseTerms'

EstimatedInstalledBytes="225000000"

EstimatedInstallSeconds="420">

      <InstallConditions>

        <BypassIf Property="ProcessorArchitecture" Compare="ValueNotEqualTo" Value="amd64"/>

        <BypassIf Property="SQLVersion" Compare="ValueExists"/>

      </InstallConditions>

      <ExitCodes>

        <ExitCode Value="0" Result="Success"/>

        <ExitCode Value="1641" Result="SuccessReboot"/>

        <ExitCode Value="3010" Result="SuccessReboot"/>

        <!-- 0x84BE0BC2 (1214,3010) -->

        <ExitCode Value="-2067919934" Result="FailReboot"/>

        <!-- 0x84C10BC2 (1217,3010) -->

        <ExitCode Value="-2067723326" Result="FailReboot"/>

        <!-- 0x84BE0007 (1214,7) -->

        <ExitCode Value="-2067922937" Result="Fail" String="AdminRequired"/>

        <!-- 0x84C4001F (1220,31) -->

        <ExitCode Value="-2067529697" Result="Fail" String="AdminRequired"/>

        <!-- 0x84BE0001 (1214,1)-->

        <ExitCode Value="-2067922943" Result="Fail" String="InvalidPlatformOSServicePacks"/>

        <!-- 0x84C4000B (1220,11) -->

        <ExitCode Value="-2067529717" Result="Fail" String="AnotherInstanceRunning"/>

        <!-- 0x84BE01F8 (1214,504) -->

        <ExitCode Value="-2067922440" Result="Fail" String="BetaComponentsFailure"/>

        <!-- 0x84BE01FA (1214,506) -->

        <ExitCode Value="-2067922438" Result="Fail" String="BetaComponentsFailure"/>

        <!-- 0x84BE0202 (1214,514) -->

        <ExitCode Value="-2067922430" Result="Fail" String="InvalidPlatformArchitecture"/>

        <!-- 0x84BE0203 (1214,515) -->

        <ExitCode Value="-2067922429" Result="Fail" String="InvalidPlatformArchitecture"/>

        <ExitCode Value="216" Result="Fail" String="InvalidPlatformArchitecture"/>

        <DefaultExitCode Result="Fail" FormatMessageFromSystem="true" String="GeneralFailure" />

      </ExitCodes>

    </Command>


    <!-- Defines an upgrade installation (amd64) -->

    <Command PackageFile="SQLEXPR_x64_ENU.EXE"

Arguments="/q /hideconsole /action=Upgrade /instancename=MVXBM /skiprules=RebootRequiredCheck /IAcceptSQLServerLicenseTerms"

EstimatedInstalledBytes="225000000"

EstimatedInstallSeconds="420">

      <InstallConditions>

        <BypassIf Property="ProcessorArchitecture" Compare="ValueNotEqualTo" Value="amd64"/>

        <BypassIf Property="SQLVersion" Compare="ValueNotExists"/>

        <BypassIf Property="SQLVersion" Compare="ValueEqualTo" Value="10.50.1600.1"/>

      </InstallConditions>

      <ExitCodes>

        <ExitCode Value="0" Result="Success"/>

        <ExitCode Value="1641" Result="SuccessReboot"/>

        <ExitCode Value="3010" Result="SuccessReboot"/>

        <!-- 0x84BE0BC2 (1214,3010) -->

        <ExitCode Value="-2067919934" Result="FailReboot"/>

        <!-- 0x84C10BC2 (1217,3010) -->

        <ExitCode Value="-2067723326" Result="FailReboot"/>

        <!-- 0x84BE0007 (1214,7) -->

        <ExitCode Value="-2067922937" Result="Fail" String="AdminRequired"/>

        <!-- 0x84C4001F (1220,31) -->

        <ExitCode Value="-2067529697" Result="Fail" String="AdminRequired"/>

        <!-- 0x84BE0001 (1214,1)-->

        <ExitCode Value="-2067922943" Result="Fail" String="InvalidPlatformOSServicePacks"/>

        <!-- 0x84C4000B (1220,11) -->

        <ExitCode Value="-2067529717" Result="Fail" String="AnotherInstanceRunning"/>

        <!-- 0x84BE01F8 (1214,504) -->

        <ExitCode Value="-2067922440" Result="Fail" String="BetaComponentsFailure"/>

        <!-- 0x84BE01FA (1214,506) -->

        <ExitCode Value="-2067922438" Result="Fail" String="BetaComponentsFailure"/>

        <!-- 0x84BE0202 (1214,514) -->

        <ExitCode Value="-2067922430" Result="Fail" String="InvalidPlatformArchitecture"/>

        <!-- 0x84BE0203 (1214,515) -->

        <ExitCode Value="-2067922429" Result="Fail" String="InvalidPlatformArchitecture"/>

        <ExitCode Value="216" Result="Fail" String="InvalidPlatformArchitecture"/>

        <DefaultExitCode Result="Fail" FormatMessageFromSystem="true" String="GeneralFailure" />

      </ExitCodes>

    </Command>


  </Commands>


  <Strings>

    <String Name="DisplayName">SQL Server 2008 R2 Express - MVXBM</String>

    <String Name="Culture">en</String>

    <String Name="SqlExpr32Exe">http://download.microsoft.com/download/5/1/a/51a153f6-6b08-4f94-a7b2-ba1ad482bc75/SQLEXPR32_x86_ENU.exe</String>

    <String Name="SqlExpr64Exe">http://download.microsoft.com/download/5/1/a/51a153f6-6b08-4f94-a7b2-ba1ad482bc75/SQLEXPR_x64_ENU.exe</String>

    <String Name="AdminRequired">You do not have the permissions required to install SQL Server 2008 R2 Express. Please contact your administrator.</String>

    <String Name="GeneralFailure">An error occurred attempting to install SQL Server 2008 R2 Express.</String>

    <String Name="InvalidPlatformXP">Windows XP Service Pack 2 or later is required to install SQL Server 2008 R2 Express.</String>

    <String Name="InvalidPlatform2K3">Windows 2003 Service Pack 2 or later is required to install SQL Server 2008 R2 Express.</String>

    <String Name="MissingMSXml">SQL Server 2008 R2 Express requires MSXML. Please ensure MSXML is installed properly.</String>

    <String Name="InsufficientHardware">The current system does not meet the minimum hardware requirements for SQL Server 2008 R2 Express. Contact your application vendor.</String>

    <String Name="InvalidPlatformOSServicePacks">The current operating system does not meet Service Pack level requirements for SQL Server 2008 R2 Express. Install the most recent Service Pack from the Microsoft download center at http://www.microsoft.com/downloads before continuing setup.</String>

    <String Name="InvalidPlatformIE">This version of SQL Server 2008 R2 Express requires Internet Explorer version 6.0 with SP1 or later. To proceed, install or upgrade to a required version of Internet Explorer and then run setup again.</String>

    <String Name="AnotherInstanceRunning">Another instance of setup is already running. The running instance must complete before this setup can proceed.</String>

    <String Name="BetaComponentsFailure">A beta version of the .NET Framework 2.0 or SQL Server was detected on the computer. Uninstall any previous beta versions of SQL Server 2008 R2 components, SQL Server Support Files, or .NET Framework 2.0 before continuing.</String>

    <String Name="InvalidPlatformArchitecture">This version of SQL Server 2008 R2 Express is not supported for the current processor architecture.</String>

    <String Name="InvalidUpgradeNotExpress">The instance of SQL Server 2005 named 'SQLEXPRESS' is a not an instance of SQL Server Express. It cannot be upgraded to SQL Server 2008 R2 Express.</String>

    <String Name="InvalidUpgradeNotExpressCore">The instance of SQL Server 2005 Express named 'SQLEXPRESS' contains components that are not included in SQL Server 2008 R2 Express. SQL Server 2008 R2 Express SP1 cannot upgrade this instance. Please use SQL Server 2008 R2 Express with Advanced Services instead.</String>

    <String Name="InvalidUpgradeLanguage">The instance of SQL Server 2005 Express named 'SQLEXPRESS' is a different language version than this SQL Server 2008 R2 Express. SQL Server 2008 R2 Express cannot upgrade this instance.</String>

    <String Name="InvalidUpgradeWoW">SQL Server 2008 R2 Express (x64) cannot upgrade the existing instance of SQL Server 2005 Express (x64 WoW) named 'SQLEXPRESS'. Uninstall this instance of SQL Server 2005 Express and retry installing SQL Server 2008 R2 Express (x64).</String>

  </Strings>

</Package>

The code in this project is built for SQL2005, but it looks like it could pretty easily be used to deploy SQL2008.

http://www.codeproject.com/KB/applications/NET_Installer_With_SQLEXP.aspx

It also supports an instance name of your choice. It will need some tweaking for sure, but it seems to support the basic tenants of what you're trying to do.

I'm going to go ahead and answer my own question for the sake of anyone else who comes looking for this sort of information on SO...from everything that I've been able to tell, it just isn't possible to install a custom instance of SQL Server (2008 anyway, and probably 2005) that is linked to the installation of custom software without going down the road of either a custom bootstrapper or a third-party installer product (InstallShield and the like). It sounds like SQL Server Compact edition might be better suited.

Don't know if anyone is still tracking this. Perhaps you could take a look at this:

http://msdn.microsoft.com/en-us/library/dd981032(SQL.100).aspx

Haven't tried it, but am looking to solve exactly the same issue posted by Adam.

One approach would be to include the SQL Server 2008 Express install package and then use a custom action in your Windows installer to fire off the silent, background installation of SQL Server 2008 Express.

The package is a standard MSI package - you should be able to set a boatload of properties on the command-line, when installing the MSI.

Here's a sample I found:

sqlexpr.exe /qb instancename="MACHINENAMESQLEXPRESS2008" 
SQLAUTOSTART=1 SAPWD="PWD" SECURITYMODE=SQL DISABLENETWORKPROTOCOLS=0"

The full list of command line properties ought to be available at Microsoft or in the help file for SQL Server 2008 Express somewhere, I'm sure.

Marc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!