sqlpackage error "Object reference not set to an instance of an object." message

120 Views Asked by At

I got below error:

C:\source>sqlpackage /Action:Script  /SourceFile:".\src\Databases\Demo.Build\publish\Demo.Build.dacpac"  /OutputPath:".\test.sql"  /TargetServerName:demo.database.windows.net    
/TargetDatabaseName:DemoDB  /TargetUser:demo  /TargetPassword:demo /p:IncludeCompositeObjects=true   /p:DoNotAlterChangeDataCaptureObjects=False  /p:IgnoreIndexOptions=True  
/p:IgnoreWithNocheckOnForeignKeys=True  /p:IgnorePermissions=True  /p:IgnoreRoleMembership=True  /p:BlockOnPossibleDataLoss=False   /p:BlockWhenDriftDetected=False  
/p:GenerateSmartDefaults=True  /p:DropIndexesNotInSource=False  /p:DropObjectsNotInSource=False  /p:ScriptDatabaseOptions=False  /p:DropStatisticsNotInSource=False  
/p:DoNotAlterReplicatedObjects=False  /p:IgnoreNotForReplication=True /p:AllowIncompatiblePlatform=True
Generating publish script for database 'DemoDB' on server 'demo.database.windows.net'.
*** A project which specifies SQL Server 2019 as the target platform may experience compatibility issues with Microsoft Azure SQL Database v12.
Time elapsed 0:00:27.16
*** An unexpected failure occurred: Object reference not set to an instance of an object.
  • SqlPackage Version: 161.8089.0
  • .NET Framework (Windows-only) or .NET Core: 7.0.203

It should pass the execution.

It turns out while building the "Demo.Build.dacpac", it shows warning messages:

dotnet build src/Databases/Demo.Build/Demo.Build.csproj -c Release -o src/Databases/Demo.Build/publish

...

warning SQL71502: SqlProcedure: [dbo].[SP_Demo] has an unresolved reference to objec
t [dbo].[sp_executesql].

However, we can manage to fix it by adding: <PackageReference Include="Microsoft.SqlServer.Dacpacs" Version="150.0.0" DacpacName="master" /> to its /src/Databases/Demo.Build/Demo.Build.csproj file. It then can build passed! But while working on sqlpackage, it shows Object reference not set to an instance of an object.

Can someone enlighten how to fix/workaround the issue?

0

There are 0 best solutions below