We are deploying to MS SQL Server
localdb
for integration testing.
We build a Database Project and the resulting dacpac
file is copied in order to be used by the IntegrationTests project. So far we have:
DatabaseProject.sqlproj
bin/debug/DatabaseProject.dacpac
IntegrationTests.csproj
bin/debug/DatabaseProject.dacpac
We have an assembly setup in the IntegrationTests project where a new fresh database is created and the dacpac
is deployed to localdb
. In the TearDown the database is deleted so we have a deterministic state for testing.
This is the code that deploys the dacpac
, which 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
);
}
We are having now a couple of database projects, and it takes about 8s to deploy each one. That increases the overall time to execute the tests.
Is it possible somehow to improve the deploy performance of the dacpac
?
dacservices
might be comparing all the objects in the dacpac to their counterparts in the empty database. – Calcicole