Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6381279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:22:32+00:00 2026-05-25T02:22:32+00:00

I am using a SQL 2008 database project (in visual studio) to manage the

  • 0

I am using a SQL 2008 database project (in visual studio) to manage the schema and initial test data for my project. The atabase project uses a post deployment which includes a number of other scripts using SQLCMD’s “:r ” syntax.

I would like to be able to conditionally include certain files based on a SQLCMD variable. This will allow me to run the project several times with our nightly build to setup various version of the database with different configurations of the data (for a multi-tenant system).

I have tried the following:

IF ('$(ConfigSetting)' = 'Configuration1')
  BEGIN
    print 'inserting specific configuration' 
:r .\Configuration1\Data.sql
  END
ELSE
  BEGIN
    print 'inserting generic data' 
:r .\GenericConfiguration\Data.sql
  END

But I get a compilation error:
SQL01260: A fatal parser error occurred: Script.PostDeployment.sql

Has anyone seen this error or managed to configure their postdeployment script to be flexible in this way? Or am I going about this in the wrong way completely?

Thanks,
Rob

P.S. I’ve also tried changing this around so that the path to the file is a variable, similar to this post. But this gives me an error saying that the path is incorrect.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:22:33+00:00Added an answer on May 25, 2026 at 2:22 am

    UPDATE

    I’ve now discovered that the if/else syntax above doesn’t work for me because some of my linked scripts require a GO statement. Essentially the :r just imports the scripts inline, so this becomes invalid sytax.

    If you need a GO statement in the linked scripts (as I do) then there isn’t any easy way around this, I ended up creating several post deployment scripts and then changing my project to overwrite the main post depeployment script at build time depending on the build configuration. This is now doing what I need, but it seems like there should be an easier way!

    For anyone needing the same thing – I found this post useful

    So in my project I have the following post deployment files:

    • Script.PostDeployment.sql (empty file which will be replaced)
    • Default.Script.PostDeployment.sql (links to scripts needed for standard data config)
    • Configuration1.Script.PostDeployment.sql (links to scripts needed for a specific data config)

    I then added the following to the end of the project file (right click to unload and then right click edit):

      <Target Name="BeforeBuild">
          <Message Text="Copy files task running for configuration: $(Configuration)" Importance="high" />
          <Copy Condition=" '$(Configuration)' == 'Release' " SourceFiles="Scripts\Post-Deployment\Default.Script.PostDeployment.sql" DestinationFiles="Scripts\Post-Deployment\Script.PostDeployment.sql" OverwriteReadOnlyFiles="true" />
          <Copy Condition=" '$(Configuration)' == 'Debug' " SourceFiles="Scripts\Post-Deployment\Default.Script.PostDeployment.sql" DestinationFiles="Scripts\Post-Deployment\Script.PostDeployment.sql" OverwriteReadOnlyFiles="true" />
          <Copy Condition=" '$(Configuration)' == 'Configuration1' " SourceFiles="Scripts\Post-Deployment\Configuration1.Script.PostDeployment.sql" DestinationFiles="Scripts\Post-Deployment\Script.PostDeployment.sql" OverwriteReadOnlyFiles="true" />
      </Target>
    

    Finally, you will need to setup matching build configurations in the solution.

    Also, for anyone trying other work arounds, I also tried the following without any luck:

    1. Creating a post build event to copy the files instead of having to hack the project file XML. i couldn’t get this to work because I couldn’t form the correct path to the post deployment script file. This connect issue describes the problem

    2. Using variables for the script path to pass to the :r command. But I came across several errors with this approach.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've added a SQL Server 2008 database project to my Visual Studio 2010 Professional
I'm using MS Visual Studio 2010 to create an application with SQL Server 2008
I have made an application project in Visual Studio 2008 C#, SQL Server from
Using Visual Studio 2010 SP1, SQL server 2008: Motherboard recently failed and I migrated
I use Visual Studio 2008 database project for managing my database scripts and version
I'm working on a C# project using a SQL Server 2008 database. There are
I am working on a project which uses a relational database (SQL Server 2008).
I'm developing a Windows Forms application using Visual Studio 2008 C# that uses an
I am using built-in SQL Server 2005 that comes along with Visual Studio 2008.
I'm using a hosting service which allows me to backup my SQL 2008 database

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.