locked
Remove DB Context Checks RRS feed

  • Question

  • Hello

    When I create a deployment script it adds some checks at the start of the scripts. (see below)
    How can I disable to generate while build. I would like to have a script, deployable on any database and on any server, independetly from specific server-names and database-names. That's why I don't need this checks.

    Thanks

    IF (DB_ID(N'$(DatabaseName)') IS NOT NULL
        AND DATABASEPROPERTYEX(N'$(DatabaseName)','Status') <> N'ONLINE')
    BEGIN
        RAISERROR(N'The state of the target database, %s, is not set to ONLINE. To deploy to this database, its state must be set to ONLINE.', 16, 127,N'$(DatabaseName)') WITH NOWAIT
        RETURN
    END
    
    GO
    
    IF NOT EXISTS (SELECT 1 FROM [master].[dbo].[sysdatabases] WHERE [name] = N'$(DatabaseName)')
    BEGIN
        RAISERROR(N'You cannot deploy this update script to target MYSERVER. The database for which this script was built, MYDATABASE, does not exist on this server.', 16, 127) WITH NOWAIT
        RETURN
    END
    
    GO
    
    IF (@@servername != 'MYSERVER')
    BEGIN
        RAISERROR(N'The server name in the build script %s does not match the name of the target server %s. Verify whether your database project settings are correct and whether your build script is up to date.', 16, 127,N'MYSERVER',@@servername) WITH NOWAIT
        RETURN
    END
    
    GO
    
    IF CAST(DATABASEPROPERTY(N'$(DatabaseName)','IsReadOnly') as bit) = 1
    BEGIN
        RAISERROR(N'You cannot deploy this update script because the database for which it was built, %s , is set to READ_ONLY.', 16, 127, N'$(DatabaseName)') WITH NOWAIT
        RETURN
    END
    
    GO
    IF EXISTS (SELECT 1
               FROM   [master].[dbo].[sysdatabases]
               WHERE  [name] = N'$(DatabaseName)')
    
    ----
    Wednesday, January 6, 2010 3:55 PM

Answers

  • There is an option in the sqldeployment configuration for GenerateDeployStateChecks which is enabled by default.  You could uncheck that and those statements will not show in the generated deploy script. 

    But, since each script generated when you deploy is specific to the target database connection, have you looked into the use of VSDBCMD?  http://msdn.microsoft.com/en-us/library/dd193283.aspx

    VSDBCMD will allow you build once and deploy to multiple servers\databases by simply adjusting a few commandline parameters.  This is IMO the best approach as, although I'm sure they are meant to be the same, there is a chance that not all of the databases you may choose to target with the script mentioned above will have the same schema.  Each deployment using VSDBCMD will generate\execute a script specific to each target.

    Andrew
    • Proposed as answer by Nantox Wednesday, January 6, 2010 5:49 PM
    • Marked as answer by Edwer FangModerator Friday, January 8, 2010 8:39 AM
    Wednesday, January 6, 2010 5:49 PM