Boost your dacpac deployment performance with C #

We are deploying for MS SQL Server localdbintegration testing.

We are building a database project, and the resulting file is dacpaccopied for use in the IntegrationTests project. So far we have:

DatabaseProject.sqlproj
    bin/debug/DatabaseProject.dacpac
IntegrationTests.csproj 
    bin/debug/DatabaseProject.dacpac

We have an assembly in the IntegrationTests project, where a new new database is created, and dacpac- localdb. In TearDown, the database is deleted, so we have a deterministic state for testing.

This is the code that deploys dacpacthat uses DacServices( Microsoft.SqlServer.Dac, System.Data.SqlLocalDb, System.Data.SqlClient):

public void CreateAndInitializeFromDacpac(
ISqlLocalDbInstance localDbInstance,
string databaseName,
string connectionString,
string dacpacPath)
{

    using (var cx = localDbInstance.CreateConnection())
    {
        cx.Open();
        using (var command = new SqlCommand(
            string.Format("CREATE DATABASE {0}", databaseName), cx))
            command.ExecuteNonQuery();
    }

    var svc = new DacServices(connectionString);

    svc.Deploy(
        DacPackage.Load(dacpacPath),
        databaseName,
        true
        );
}

Now we have a couple of database projects, and deployment requires 8s . This increases the overall test execution time.

- dacpac?

+4
1

!

, , SSDT , , .

:

var dacOptions = new DacDeployOptions { 
               CreateNewDatabase = true
            };

svc.Deploy(
    DacPackage.Load(dacpacPath),
    databaseName,
    true, 
    options: dacOptions
    );

, SSDT , , - , Microsoft.Data.Tools.Schema.Sql.dll Microsoft.Data.Tools.Schema.Sql.Deployment.SqlDeploymentPlanGenerator.OnInitialize(SqlDeployment). , T-SQL .

, , , , , SSDT , , , , !

, Parallel.Foreach, TheGameiswar.

+3
source

Source: https://habr.com/ru/post/1674644/


All Articles