2

I have a SQL Server database project that can deploy the schema to a database, it creates a .dacpac and applies it to a database.

I would like to use the SQL file generated in an automated test class that will create all the tables and objects to an empty database.

I can't use the generated SQL file because it contains unrecognized commands like

:setvar DatabaseName "MyDB"
:setvar DefaultFilePrefix "MyDB"

How can I generate an executable SQL script from a SQL Server database project deployment?

4

1 Answer 1

2

Thanks to xLiSPirit and this SO post, I ended up making it work with the DacServices class and this piece of code :

    private void UpgradeDatabaseWithDacpac(string connectionString, string databaseName, string dacpacFileName)
    {
        DacPackage dacPackage = DacPackage.Load(dacpacFileName);
        DacServices dacServices = new DacServices(connectionString);
        dacServices.Deploy(dacPackage, databaseName, true);
    }  
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.