I am referencing a database project during publish in a second database project. For easier reference, let's call them Database
and Database.Tests
.
Database
is being referenced by Database.Tests
During deployment the Database project will be deployed twice to the same machine. Once as "Database" and once as part of "Database.Tests"
Doing this manually using the publish option is working as expected, however when using SqlPackage.exe I am running into an error when publishing the seoncd database:
*** Could not deploy package.
Error SQL72014: .Net SqlClient Data Provider: Msg 33415, Level 16, State 4, Line 5 FILESTREAM DIRECTORY_NAME 'AZE' attempting to be set on database 'Database.Tests' is not unique in this SQL Server instance. Provide a unique value for the database option FILESTREAM DIRECTORY_NAME to enable non-transacted access.
Error SQL72045: Script execution error. The executed script:
IF EXISTS (SELECT 1
FROM [master].[dbo].[sysdatabases]
WHERE [name] = N'$(DatabaseName)')
BEGIN
ALTER DATABASE [$(DatabaseName)]
SET FILESTREAM(NON_TRANSACTED_ACCESS = FULL, DIRECTORY_NAME = N'AZE'),
CONTAINMENT = NONE
WITH ROLLBACK IMMEDIATE;
END
Here is what I am doing. the first thing is to create the test database. To do that I am deploying tSQLt, the Database project and lastly the database.tests project using the following sqlPackage.exe commands:
"C:\Program Files\Microsoft SQL Server\150\DAC\bin\SqlPackage.exe" /Action:Publish ^
/SourceFile:"Database.dacpac" ^
/TargetDatabaseName:"Database.Tests" ^
/TargetServerName:"server\instance" ^
/v:MSSQL_USER="some_user" ^
/v:MSSQL_PASSWORD="somepassword"
"C:\Program Files\Microsoft SQL Server\150\DAC\bin\SqlPackage.exe" /Action:Publish ^
/SourceFile:"Database.dacpac" ^
/TargetDatabaseName:"Database.Tests" ^
/TargetServerName:"server\instance"
"C:\Program Files\Microsoft SQL Server\150\DAC\bin\SqlPackage.exe" /Action:Publish ^
/SourceFile:"Database.Tests.dacpac" ^
/TargetDatabaseName:"Database.Tests" ^
/TargetServerName:"server\instance"
# at this point we deploy the second database into a database called `Database`
"C:\Program Files\Microsoft SQL Server\150\DAC\bin\SqlPackage.exe" /Action:Publish ^
/SourceFile:"Database.dacpac" ^
/TargetDatabaseName:"Database" ^
/TargetServerName:"server\instance" ^
/v:MSSQL_USER="some_user" ^
/v:MSSQL_PASSWORD="somepassword"
Can I dynamically change the filestream directory setting at deployment-time or circumvent this issue in some other way? In theory I only need the schema, sprocs and functions from the Database
project in my test database to execute my tSQLt tests and nothing else.