I'm running into the same issue mentioned here on the Microsoft docs page: https://github.com/MicrosoftDocs/sql-docs/issues/4230
It looks like the registration part is failing in .NET Core, both when using the package (I've tried basically all versions) and when running sqlpackage manually. Here's my code in C#
var connectionString = $"Data Source=tcp:{dbServer}.database.windows.net,1433;Initial Catalog={dbName};User ID={dbUser}@{dbServer};Password={dbPassword};Integrated Security=False;Encrypt=True";
var dacServices = new DacServices(connectionString);
using var dacPackage = DacPackage.Load(dacpacFileStream);
var dacDeployOptions = new DacDeployOptions
{
CommandTimeout = (int)TimeSpan.FromMinutes(25).TotalSeconds,
BlockWhenDriftDetected = false,
DropConstraintsNotInSource = true,
DropObjectsNotInSource = true,
DropIndexesNotInSource = true,
RegisterDataTierApplication = true,
ScriptDatabaseOptions = false
};
dacServices.Deploy(dacPackage, dbName, true, dacDeployOptions);
The exception I'm getting has an InnerException of type Microsoft.Data.Tools.Schema.Sql.Deployment.DeploymentFailedException with the message Unable to register data-tier application: Cannot get stream with FileMode.Create, FileMode.CreateNew, FileMode.Truncate, FileMode.Append when access is FileAccess.Read.
The issue seems to be registering in the master table, I've drilled it down to:
var connectionString = $"Data Source=tcp:{dbServer}.database.windows.net,1433;Initial Catalog={dbName};User ID={dbUser}@{dbServer};Password={dbPassword};Integrated Security=False;Encrypt=True";
var dacServices = new DacServices(connectionString);
dacServices.Register(request.DbName, dacPackage.Name, dacPackage.Version, dacPackage.Description);
which still ends with the same exception.
You can reproduce it in the .NET Core version of sqlpackage like this:
sqlpackage /a:publish /sf:.\MyDacpac-version.dacpac /tcs:"Data Source=tcp:dbServer.database.windows.net,1433;Initial Catalog=dbName;User ID=dbUser@dbServer;Password=dbPassword;Integrated Security=False;Encrypt=True" /p:RegisterDataTierApplication=true /d:True
The diagnostics ouput traces this exception:
Microsoft.Data.Tools.Diagnostics.Tracer Error: 0 : 2020-04-02T08:22:48 : System.ArgumentException: Cannot get stream with FileMode.Create, FileMode.CreateNew, FileMode.Truncate, FileMode.Append when access is FileAccess.Read.
at Microsoft.Data.Tools.Schema.Sql.Packaging.Package.Open(String path, FileMode packageMode, FileAccess packageAccess, FileShare packageShare) in F:\B\16846\6200\Sources\Product\Source\SchemaSql\Packaging\Package.cs:line 841
at Microsoft.Data.Tools.Schema.Sql.Build.SqlPackage.Artifact.InitializefromFile(FileInfo fileInfo, FileMode mode, FileAccess access) in F:\B\16846\6200\Sources\Product\Source\SchemaSql\Build\SqlPackage.Artifact.cs:line 251
Microsoft.Data.Tools.Diagnostics.Tracer Error: 19 : 2020-04-02T08:22:48 : Microsoft.SqlServer.Dac.DacServicesException: Could not deploy package.
---> Microsoft.Data.Tools.Schema.Sql.Deployment.DeploymentFailedException: Unable to register data-tier application: Cannot get stream with FileMode.Create, FileMode.CreateNew, FileMode.Truncate, FileMode.Append when access is FileAccess.Read. ---> Microsoft.Data.Tools.Schema.Sql.Build.SqlPackageException: Cannot get stream with FileMode.Create, FileMode.CreateNew, FileMode.Truncate, FileMode.Append when access is FileAccess.Read. ---> System.ArgumentException: Cannot get stream with FileMode.Create, FileMode.CreateNew, FileMode.Truncate, FileMode.Append when access is FileAccess.Read.
at Microsoft.Data.Tools.Schema.Sql.Packaging.Package.Open(String path, FileMode packageMode, FileAccess packageAccess, FileShare packageShare) in F:\B\16846\6200\Sources\Product\Source\SchemaSql\Packaging\Package.cs:line 841
at Microsoft.Data.Tools.Schema.Sql.Build.SqlPackage.Artifact.InitializefromFile(FileInfo fileInfo, FileMode mode, FileAccess access) in F:\B\16846\6200\Sources\Product\Source\SchemaSql\Build\SqlPackage.Artifact.cs:line 251
--- End of inner exception stack trace ---
at Microsoft.Data.Tools.Schema.Sql.Build.SqlPackage.Artifact.InitializefromFile(FileInfo fileInfo, FileMode mode, FileAccess access) in F:\B\16846\6200\Sources\Product\Source\SchemaSql\Build\SqlPackage.Artifact.cs:line 281
at Microsoft.Data.Tools.Schema.Sql.Build.SqlPackage.Open(FileInfo fileInfo, FileAccess access) in F:\B\16846\6200\Sources\Product\Source\SchemaSql\Build\SqlPackage.cs:line 71
at Microsoft.Data.Tools.Schema.Sql.Deployment.SqlDeploymentRegistrar.GenerateTemporaryPackage(DacMetadata metadata, SqlSchemaModel model) in F:\B\16846\6200\Sources\Product\Source\SchemaSql\Deployment\SqlDeploymentRegistrar.cs:line 224
at Microsoft.Data.Tools.Schema.Sql.Deployment.SqlDeploymentRegistrar.Register(DacMetadata metadata, ModelStorageType modelStorageType, Guid dacInstanceId) in F:\B\16846\6200\Sources\Product\Source\SchemaSql\Deployment\SqlDeploymentRegistrar.cs:line 131
at Microsoft.Data.Tools.Schema.Sql.Deployment.SqlDeployment.RegisterSchema(Guid dacInstanceId) in F:\B\16846\6200\Sources\Product\Source\SchemaSql\Deployment\SqlDeployment.cs:line 1907
--- End of inner exception stack trace ---
at Microsoft.Data.Tools.Schema.Sql.Deployment.SqlDeployment.RegisterSchema(Guid dacInstanceId) in F:\B\16846\6200\Sources\Product\Source\SchemaSql\Deployment\SqlDeployment.cs:line 1924
at Microsoft.Data.Tools.Schema.Sql.Deployment.SqlDeployment.Controller.RegisterSchema(Guid dacInstanceId) in F:\B\16846\6200\Sources\Product\Source\SchemaSql\Deployment\SqlDeployment.Controller.cs:line 322
at Microsoft.SqlServer.Dac.DeployOperation.<CreateRegisterOperation>b__22_0(Object operation, CancellationToken token) in F:\B\16846\6200\Sources\Product\Source\DeploymentApi\DeployOperation.cs:line 304
at Microsoft.SqlServer.Dac.Operation.Microsoft.SqlServer.Dac.IOperation.Run(OperationContext context) in F:\B\16846\6200\Sources\Product\Source\DeploymentApi\Operation.cs:line 72
at Microsoft.SqlServer.Dac.ReportMessageOperation.Microsoft.SqlServer.Dac.IOperation.Run(OperationContext context) in F:\B\16846\6200\Sources\Product\Source\DeploymentApi\ReportMessageOperation.cs:line 44
at Microsoft.SqlServer.Dac.DeployOperation.Microsoft.SqlServer.Dac.IOperation.Run(OperationContext context) in F:\B\16846\6200\Sources\Product\Source\DeploymentApi\DeployOperation.cs:line 470
followed by this is the error output of the console:
*** Could not deploy package.
Unable to register data-tier application: Cannot get stream with FileMode.Create, FileMode.CreateNew, FileMode.Truncate, FileMode.Append when access is FileAccess.Read.
Cannot get stream with FileMode.Create, FileMode.CreateNew, FileMode.Truncate, FileMode.Append when access is FileAccess.Read.
Any idea what's going on here?
I'm running into the same issue mentioned here on the Microsoft docs page: https://github.com/MicrosoftDocs/sql-docs/issues/4230
It looks like the registration part is failing in .NET Core, both when using the package (I've tried basically all versions) and when running
sqlpackagemanually. Here's my code in C#The exception I'm getting has an InnerException of type
Microsoft.Data.Tools.Schema.Sql.Deployment.DeploymentFailedExceptionwith the messageUnable to register data-tier application: Cannot get stream with FileMode.Create, FileMode.CreateNew, FileMode.Truncate, FileMode.Append when access is FileAccess.Read.The issue seems to be registering in the master table, I've drilled it down to:
which still ends with the same exception.
You can reproduce it in the .NET Core version of
sqlpackagelike this:The diagnostics ouput traces this exception:
followed by this is the error output of the console:
Any idea what's going on here?