DacFx: SqlPackage Publish fails in some conditions with "ISqlModelElement: Identifier part cannot be null"

  • SqlPackage or DacFx Version: 162.2.111.2
  • .NET Framework (Windows-only) or .NET Core:
  • Environment (local platform and source/target platforms):
    • Teamcity agent: Windows Server 2012 R2
    • Microsoft SQL Server 2019 (RTM-CU25) - 15.0.4355.3 (X64)
    • Compatibility Level: 150

Steps to Reproduce:

In PR build of TSQL projects we run tSQLt tests in DB clone. For that we create DB clone on the fly and deploy corresponding dacpac with tests into this clone. This scenario works like a charm in all projects except one. The project is one of our In-Memory DBs; for the rest of In-Memory DBs described scenario works like a charm. The problematic DB can be deployed on “normal” DB (not clone) with no issues; sqlpackage params are the same, dacpac is exactly the same.

The problem can be reproduced on this project at any time, it is stable. But I have no glue what could be the cause of the problem.

SqlPackage params:

& 'C:\Program Files\Microsoft SQL Server\160\dac\bin\sqlpackage.exe' /Action:Publish /SourceFile:'C:\BuildAgent\temp\buildTmp\output_build\post_trade_test.dacpac' /TargetConnectionString:"Data Source=our_server;Initial Catalog='_tsqlt_temp_clone__post_trade';Connect Timeout=60;Integrated Security=True;TrustServerCertificate=True;Persist Security Info=False;Pooling=False;MultipleActiveResultSets=False;Encrypt=False" 
/p:ExcludeObjectType=Logins /p:ExcludeObjectType=RoleMembership /p:ExcludeObjectType=Users /p:ExcludeObjectType=Permissions 
/p:ExcludeObjectType=PartitionFunctions /p:ExcludeObjectType=PartitionSchemes /p:IgnoreIndexOptions=True  /p:IgnoreTableOptions=True /p:DatabaseLockTimeout=60 /p:CommandTimeout=150 
/p:DropObjectsNotInSource=True /p:DropStatisticsNotInSource=False /p:IgnoreObjectPlacementOnPartitionScheme=true 
/p:IgnorePartitionSchemes=true /p:IgnoreTablePartitionOptions=true /p:ScriptDatabaseOptions=False /p:DropPermissionsNotInSource=False /p:DropRoleMembersNotInSource=False 
/p:AdditionalDeploymentContributors=AgileSqlClub.DeploymentFilterContributor /p:AdditionalDeploymentContributorArguments='SqlPackageFilter0=IgnoreType(Statistics);SqlPackageFilter1=IgnoreSchema(tmp)' 
/p:BlockOnPossibleDataLoss=False /p:IncludeCompositeObjects=True /Profile:'post_trade\post_trade_test\Publish\post_trade_test.publish.xml'

Tail of SqlPackage Publish log with /d switch:

Details
Microsoft.Data.Tools.Diagnostics.Tracer Verbose: 25 : 2024-02-28T19:04:28 : Perf: Operation started (name, details): Top Level Populator,Sql150ExternalTablePopulator
Microsoft.Data.Tools.Diagnostics.Tracer Information: 0 : 2024-02-28T19:04:28 : Populating child populator : Sql150ExternalTableColumnPopulator
Microsoft.Data.Tools.Diagnostics.Tracer Verbose: 1 : 2024-02-28T19:04:28 : Executing populator:
Sql150ExternalTableColumnPopulator

Microsoft.Data.Tools.Diagnostics.Tracer Verbose: 25 : 2024-02-28T19:04:28 : Perf: Operation started (name, details): Child Populator,Sql150ExternalTableColumnPopulator Microsoft.Data.Tools.Diagnostics.Tracer Verbose: 25 : 2024-02-28T19:04:28 : Perf: Operation ended (name, details, elapsed in ms): Child Populator,Sql150ExternalTableColumnPopulator,0 Microsoft.Data.Tools.Diagnostics.Tracer Verbose: 25 : 2024-02-28T19:04:28 : Perf: Operation ended (name, details, elapsed in ms): Top Level Populator,Sql150ExternalTablePopulator,0 Microsoft.Data.Tools.Diagnostics.Tracer Information: 0 : 2024-02-28T19:04:28 : Populating populator : SqlSysCommentObjectDependencyPopulator Microsoft.Data.Tools.Diagnostics.Tracer Verbose: 1 : 2024-02-28T19:04:28 : Executing populator: SqlSysCommentObjectDependencyPopulator

Microsoft.Data.Tools.Diagnostics.Tracer Verbose: 25 : 2024-02-28T19:04:28 : Perf: Operation started (name, details): Top Level Populator,SqlSysCommentObjectDependencyPopulator Microsoft.Data.Tools.Diagnostics.Tracer Verbose: 25 : 2024-02-28T19:04:28 : Perf: Operation ended (name, details, elapsed in ms): Top Level Populator,SqlSysCommentObjectDependencyPopulator,21 Microsoft.Data.Tools.Diagnostics.Tracer Warning: 0 : 2024-02-28T19:04:28 : Reverse Engineering operation cancelled. Exception cannot be retried. Exception: Microsoft.Data.Tools.Schema.SchemaModel.ModelException: Identifier part cannot be null. at Microsoft.Data.Tools.Schema.SchemaModel.ModelStore.CheckIdentifierPartsLength(ICollection1 parts) at Microsoft.Data.Tools.Schema.SchemaModel.ModelStore.CreateIdentifierImpl(Int32 externalPartsId, ICollection1 parts) at Microsoft.Data.Tools.Schema.Sql.SchemaModel.ReverseEngineerPopulators.SqlSysCommentObjectDependencyPopulator.GetReferencedElement(Type& referencedElementType, ModelIdentifier& referencedModelId) at Microsoft.Data.Tools.Schema.Sql.SchemaModel.ReverseEngineerPopulators.SqlSysCommentObjectDependencyPopulator.CreateElement(ReverseEngineerOption option, EventArgs args) at Microsoft.Data.Tools.Schema.Sql.SchemaModel.ReverseEngineerPopulators.TopLevelElementPopulator1.Populate(SqlReverseEngineerRequest request, OrdinalSqlDataReader reader, ReverseEngineerOption option) at Microsoft.Data.Tools.Schema.Sql.SchemaModel.SqlReverseEngineerImpl.ExecutePopulators(Tuple2 connectionTuple, IList1 populators, Int32 totalPopulatorsCount, Int32 startIndex, Boolean progressAlreadyUpdated, ReverseEngineerOption option, SqlReverseEngineerRequest request) Microsoft.Data.Tools.Diagnostics.Tracer Error: 0 : 2024-02-28T19:04:28 : Unexpected exception in ExecutePopulators(). In a retail build this would go in the ErrorManager rather than being allowed to crash VS. This should never happen - known errors should be explicitly handled. Microsoft.Data.Tools.Schema.SchemaModel.ModelException: Identifier part cannot be null. at Microsoft.Data.Tools.Schema.SchemaModel.ModelStore.CheckIdentifierPartsLength(ICollection1 parts) at Microsoft.Data.Tools.Schema.SchemaModel.ModelStore.CreateIdentifierImpl(Int32 externalPartsId, ICollection1 parts) at Microsoft.Data.Tools.Schema.Sql.SchemaModel.ReverseEngineerPopulators.SqlSysCommentObjectDependencyPopulator.GetReferencedElement(Type& referencedElementType, ModelIdentifier& referencedModelId) at Microsoft.Data.Tools.Schema.Sql.SchemaModel.ReverseEngineerPopulators.SqlSysCommentObjectDependencyPopulator.CreateElement(ReverseEngineerOption option, EventArgs args) at Microsoft.Data.Tools.Schema.Sql.SchemaModel.ReverseEngineerPopulators.TopLevelElementPopulator1.Populate(SqlReverseEngineerRequest request, OrdinalSqlDataReader reader, ReverseEngineerOption option) at Microsoft.Data.Tools.Schema.Sql.SchemaModel.SqlReverseEngineerImpl.ExecutePopulators(Tuple2 connectionTuple, IList1 populators, Int32 totalPopulatorsCount, Int32 startIndex, Boolean progressAlreadyUpdated, ReverseEngineerOption option, SqlReverseEngineerRequest request) Microsoft.Data.Tools.Schema.SchemaModel.ModelException: Identifier part cannot be null. at Microsoft.Data.Tools.Schema.SchemaModel.ModelStore.CheckIdentifierPartsLength(ICollection1 parts) at Microsoft.Data.Tools.Schema.SchemaModel.ModelStore.CreateIdentifierImpl(Int32 externalPartsId, ICollection1 parts) at Microsoft.Data.Tools.Schema.Sql.SchemaModel.ReverseEngineerPopulators.SqlSysCommentObjectDependencyPopulator.GetReferencedElement(Type& referencedElementType, ModelIdentifier& referencedModelId) at Microsoft.Data.Tools.Schema.Sql.SchemaModel.ReverseEngineerPopulators.SqlSysCommentObjectDependencyPopulator.CreateElement(ReverseEngineerOption option, EventArgs args) at Microsoft.Data.Tools.Schema.Sql.SchemaModel.ReverseEngineerPopulators.TopLevelElementPopulator1.Populate(SqlReverseEngineerRequest request, OrdinalSqlDataReader reader, ReverseEngineerOption option) at Microsoft.Data.Tools.Schema.Sql.SchemaModel.SqlReverseEngineerImpl.ExecutePopulators(Tuple2 connectionTuple, IList1 populators, Int32 totalPopulatorsCount, Int32 startIndex, Boolean progressAlreadyUpdated, ReverseEngineerOption option, SqlReverseEngineerRequest request) Microsoft.Data.Tools.Diagnostics.Tracer Information: 25 : 2024-02-28T19:04:28 : Perf: Operation ended (name, details, elapsed in ms): PopulateAll,,86995 Microsoft.Data.Tools.Diagnostics.Tracer Error: 1 : 2024-02-28T19:04:28 : Error detected when reverse engineering the database. Severity:'Error' Prefix:'' Error Code:'0' Message:An error occurred while attempting to reverse engineer elements of type Microsoft.Data.Tools.Schema.Sql.SchemaModel.ISqlModelElement: Identifier part cannot be null. Microsoft.Data.Tools.Diagnostics.Tracer Error: 19 : 2024-02-28T19:04:28 : Microsoft.SqlServer.Dac.DacServicesException: An error occurred during deployment plan generation. Deployment cannot continue. Error SQL72018: ISqlModelElement could not be imported but one or more of these objects exist in your source. ---> Microsoft.Data.Tools.Schema.Sql.Deployment.DeploymentFailedException: Errors occurred while modeling the target database. Deployment can not continue. at Microsoft.Data.Tools.Schema.Sql.Deployment.SqlDeployment.ThrowIfErrors(String message, ErrorManager errors, Object category) at Microsoft.Data.Tools.Schema.Sql.Deployment.SqlDeploymentEndpointServer.OnLoad(ErrorManager errors, DeploymentEngineContext context) at Microsoft.Data.Tools.Schema.Sql.Deployment.SqlDeployment.PrepareModels() at Microsoft.Data.Tools.Schema.Sql.Deployment.SqlDeployment.InitializePlanGeneratator() at Microsoft.Data.Tools.Schema.Sql.Deployment.SqlDeployment.CreateController(Action1 msgHandler) at Microsoft.SqlServer.Dac.DacServices.CreateController(SqlDeployment deploymentEngine, ErrorManager errorManager) — End of inner exception stack trace — Microsoft.Data.Tools.Diagnostics.Tracer Information: 25 : 2024-02-28T19:04:28 : Perf: Operation ended (name, details, elapsed in ms): Initializing deployment,91748 Initializing deployment (Failed) *** An error occurred during deployment plan generation. Deployment cannot continue. Error SQL72018: ISqlModelElement could not be imported but one or more of these objects exist in your source.

Errors occurred while modeling the target database. Deployment can not continue. Microsoft.Data.Tools.Diagnostics.Tracer Information: 18 : 2024-02-28T19:04:28 : Time elapsed: 0:01:32.16. Time elapsed 0:01:32.16 Microsoft.Data.Tools.Diagnostics.Tracer Information: 0 : 2024-02-28T19:04:28 : SqlPackage completed

there is about 1.5 million lines of log above it.

Let me know if you need additional details.

Did this occur in prior versions? If not - which version(s) did it work in? on 162.0.52.1 we had the same issue

(DacFx/SqlPackage/SSMS/Azure Data Studio)

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 17 (8 by maintainers)

Most upvoted comments

@IVNSTN thanks for the detailed info. I was able to repro and fix the bug inside DacFx. The fix will be included in 162.5 release. Also, about the clone command, looks like it will be deprecated soon to copy databases, DacFx is one of the recommended options. https://www.microsoft.com/en-us/sql-server/blog/2024/03/25/announcing-the-discontinuation-of-using-dbcc-clonedatabase-command-in-production-deployments/#:~:text=DBCC CLONEDATABASE command generates a schema-only clone or,as a new database in a production environment.

@IVNSTN sorry I’m just trying to figure out the sample database to repro the bug in dacfx. cloning the database using “DBCC CLONEDATABASE command” and if it has any bug is not related to DacFx operations. we should still notify SQL Server team to report the bug. but when it creates the database, it is in a state which now causes a bug in DacFx. either with missing temporal tables or UTDs … so that is what I’m trying to fix. If dacfx operation is running on a database with missing objects, it should not throw unhandled exception. I would really appreciate if you can provide me with a small sample to create my database to be able to repro this bug in dacfx.

@IVNSTN yes I checked the logs but it doesn’t have information about which element is causing this. My guess was that "Select * is causing it but I can be wrong. I’m adding more details to the log so using the next release you can see which element is causing this. The other thing you can do is to run the following query in your target database SELECT CASE WHEN [d].[referencing_class] = 1 AND NOT [TableType].[user_type_id] IS NULL THEN [TableType].[user_type_id] ELSE [d].[referencing_id] END AS [ReferencingId], [o].[type] AS [ReferencingType], CASE WHEN [d].[referencing_class] = 1 AND NOT [TableType].[user_type_id] IS NULL THEN [TableType].[name] ELSE [o].[name] END AS [ReferencingName], [c].[name] AS [ReferencingColumnName], CASE WHEN [d].[referencing_class] = 1 AND NOT [TableType].[user_type_id] IS NULL THEN SCHEMA_NAME([TableType].[schema_id]) WHEN [d].[referencing_class] = 1 AND NOT [ParentTableType].[user_type_id] IS NULL THEN SCHEMA_NAME([ParentTableType].[schema_id]) ELSE [o].[ReferencingSchemaName] END AS [ReferencingSchemaName], [d].[referencing_minor_id] AS [ReferencingMinorId], CASE WHEN NOT [ReferencedTableType].[user_type_id] IS NULL THEN [ReferencedTableType].[user_type_id] ELSE [d].[referenced_id] END AS [ReferencedId], CASE WHEN [ReferencedTableType].[user_type_id] IS NULL AND [d].[referenced_schema_name] IS NOT NULL THEN [d].[referenced_schema_name] WHEN [d].[referenced_class] = 6 THEN SCHEMA_NAME([udt].[schema_id]) WHEN d.referenced_class = 10 THEN SCHEMA_NAME([xsc].[schema_id]) WHEN d.referenced_class = 21 THEN NULL WHEN NOT [ReferencedTableType].[user_type_id] IS NULL THEN SCHEMA_NAME([ReferencedTableType].[schema_id]) WHEN [d].[is_caller_dependent] = 1 AND [d].[referenced_class] = 1 AND [d].[referenced_schema_name] IS NULL THEN (SELECT TOP 1 SCHEMA_NAME(schema_id) FROM [sys].[objects] AS [o] WITH (NOLOCK) WHERE [o].[name] = [d].[referenced_entity_name]) ELSE OBJECT_SCHEMA_NAME([d].[referenced_id]) END AS [ReferencedSchemaName], CASE WHEN NOT [ReferencedTableType].[user_type_id] IS NULL THEN [ReferencedTableType].[name] ELSE [d].[referenced_entity_name] END AS ReferencedName, [c2].[name] AS [ReferencedColumnName], [d].[referenced_minor_id] AS [ReferencedMinorId], CASE [t].[is_filetable] WHEN 1 THEN N'UF' ELSE [o2].[type] END AS [ReferencedType], [d].[referenced_class] AS [ReferencedClass], [d].[is_caller_dependent] AS [IsCallerDependent], [d].[is_ambiguous] AS [IsAmbiguous], [np].[procedure_number] AS [ProcedureNumber], CAST(ISNULL([parent].[object_id], 0) AS BIT) AS [ReferencingParentIsTableType], CASE WHEN [d].[referencing_class]= 1 AND NOT [parent].[object_id] IS NULL THEN N'TT' ELSE [o].[type] END AS [FilterReferencingType], CASE WHEN NOT [ParentTableType].[user_type_id] IS NULL THEN [ParentTableType].[name] WHEN [d].[referencing_class] = 1 AND NOT [TableType].[user_type_id] IS NULL THEN [TableType].[name] ELSE [o].[name] END AS [FilterReferencingName], CASE WHEN NOT [ParentTableType].[user_type_id] IS NULL THEN [ParentTableType].[type_table_object_id] ELSE [o].[parent_object_id] END AS [ParentId], CASE WHEN [ParentTableType].[user_type_id] IS NOT NULL THEN [ParentTableType].[schema_id] ELSE [referencingParent].[schema_id] END AS [ParentSchemaId], CASE WHEN [o].[type] = N'TT' THEN 0 WHEN [ParentTableType].[user_type_id] IS NOT NULL THEN 0 ELSE ISNULL([o].[is_ms_shipped], 0) END AS [IsMsShipped], [t].[is_dropped_ledger_table] AS [ReferencedDroppedLedgerTable], [v].[ledger_view_type] AS [ReferencingLedgerViewType] FROM [sys].[sql_expression_dependencies] AS [d] WITH (NOLOCK) LEFT JOIN ( SELECT SCHEMA_NAME([schema_id]) AS [ReferencingSchemaName], [name], [object_id] , 1 AS [parent_class] , [type], [parent_object_id], [is_ms_shipped] FROM [sys].[objects] WITH (NOLOCK) UNION SELECT [name] AS [ReferencingSchemaName], NULL AS [name], [object_id], [parent_class], N'DT', 0 AS [parent_object_id], [is_ms_shipped] FROM [sys].[triggers] WITH (NOLOCK) where [parent_class] = 0) AS [o] ON [d].[referencing_class] in (1, 12) AND [o].[object_id] = [d].[referencing_id] LEFT JOIN [sys].[columns] AS [c] WITH (NOLOCK) ON [d].[referencing_class] = 1 AND [o].[object_id] = [c].[object_id] AND [d].[referencing_minor_id] = [c].[column_id] LEFT JOIN [sys].[objects] AS [referencingParent] WITH (NOLOCK) ON [o].[parent_object_id] = [referencingParent].[object_id] LEFT JOIN [sys].[objects] AS [o2] WITH (NOLOCK) ON [d].[referenced_class] = 1 AND [o2].[object_id] = [d].[referenced_id] LEFT JOIN [sys].[columns] AS [c2] WITH (NOLOCK) ON [d].[referenced_class] = 1 AND [d].[referenced_id] = [c2].[object_id] AND [d].[referenced_minor_id] = [c2].[column_id] LEFT JOIN [sys].[types] as [udt] WITH (NOLOCK) ON [d].[referenced_class] = 6 AND [udt].[user_type_id] = [d].[referenced_id] LEFT JOIN [sys].[xml_schema_collections] AS [xsc] WITH (NOLOCK) ON [d].[referenced_class] = 10 AND [xsc].[xml_collection_id] = [d].[referenced_id] LEFT JOIN [sys].[objects] as [parent] WITH (NOLOCK) ON [parent].[object_id] = [o].[parent_object_id] AND [parent].[type] = N'TT' LEFT JOIN [sys].[tables] AS [t] WITH (NOLOCK) ON [o2].[object_id] = [t].[object_id] LEFT JOIN [sys].[table_types] AS [ParentTableType] WITH (NOLOCK) ON [ParentTableType].[type_table_object_id] = [parent].[object_id] LEFT JOIN [sys].[table_types] AS [TableType] WITH (NOLOCK)ON [TableType].[type_table_object_id] = [o].[object_id] LEFT JOIN [sys].[table_types] AS [ReferencedTableType] WITH (NOLOCK) ON [ReferencedTableType].[type_table_object_id] = [o2].[object_id] --{0} LEFT JOIN (SELECT [object_id] , 1 AS [procedure_number] FROM [sys].[procedures] WITH (NOLOCK) union SELECT [object_id], [procedure_number] FROM [sys].[numbered_procedures] WITH (NOLOCK)) AS [np] ON [d].[referenced_id] = [np].[object_id] AND [d].[referenced_class] = 1 LEFT JOIN [sys].[views] as [v] WITH (NOLOCK) ON [d].[referencing_id] = [v].[object_id] WHERE ([o].[ReferencingSchemaName] <> N'cdc' OR [o].[parent_class] <> 1) AND [o].[type] <> N'PG' AND [d].[referenced_database_name] IS NULL AND [d].[referenced_server_name] IS NULL AND [d].[is_ambiguous] = 0 AND ([d].[is_caller_dependent] = 0 OR 1 = (SELECT COUNT(1) FROM [sys].[objects] WITH (NOLOCK) WHERE [name] = [d].[referenced_entity_name])) AND [c2].[graph_type] IS NULL ;

This will give you some info about which element is having a problem. you can check the ReferencedName column for any null value and if there’s any, then check the syntax of the element mentioned in ReferencingName column