HiveBrain v1.2.0
Get Started
← Back to all entries
debugsqlMinor

SSDT Schema Compare fails when comparing my DB Project to my Azure Server

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
failscomparingssdtprojectazurewhenservercompareschema

Problem

I have a SQL Database project that I have built our enterprise DB on. It has deployed several times on internal and AWS hosted SQL servers using SSDT's Schema Compare tool.

The problem when I post to Azure Hosted Win 2012 Server running SQL Ent 2012 sp2. It comes back with "Comparison complete. No differences detected."

I know this is wrong, because I can open Enterprise Manager and compare the schema to the SQL Project and see that there is a difference.

I found several articles talking about how the 2014 release broke the tool, but those were in version differences.

[Yes I did Google this. Stating because I am notorious in forgetting to do so. ] https://www.google.com/webhp?ie=utf-8&oe=utf-8#q=ssdt+data+compare+fail+to+detect+difference&start=10

Other things I have checked include making sure my DB account has unlimited access. I can connect with Management console. I can connect with local programs.

Last confirmation that there was a problem:

  • I created an SP that has a single return of the number 1.



  • It could have a return of nothing for the sake of testing.



  • After I created the SP, I ran schema compare on all of my instances and all but the Azure server showed the variance.



Update

I have verified that this is explicitly with the server, in that now two different users on two different computers are having the same exact problem.

Solution

TL;DR

The query Visual Studio is executing is being blocked and the query times out.

Turns out I've managed to work this out for our situation: timing out due to blocking!

I ran a profiler trace with a filter on application name of Microsoft SQL Server Data Tools, Schema Compare to capture the Visual Studio schema compare events.

It would reach a certain query and then stop, when VS would claim that the comparison was complete.

Here's the batch of queries in question:

```
select object_id as id,
null as id2,
case
when [type] != 'D ' then [type]
when parent_object_id != 0 then 'D '
else 'LD'
end as [type],
schema_name(schema_id) as name1,
name as name2,
null as name3,
null as a1,
null as v1,
modify_date as mod
from sys.objects
where
type != 'S'
and is_ms_shipped != 1

union

select principal_id as id,
null as id2,
type,
name as name1,
null as name2,
null as name3,
null as a1,
null as v1,
modify_date as mod
from sys.database_principals

union

select assembly_id as id,
null as id2,
'CLR' as type,
name as name1,
null as name2,
null as name3,
principal_id as a1,
null as v1,
modify_date as mod
from sys.assemblies
where
is_user_defined =1

union

select schema_id as id,
null as id2,
'SCH' as type,
name as name1,
null as name2,
null as name3,
principal_id as a1,
null as v1,
null as mod
from sys.schemas

union

select user_type_id as id,
null as id2,
case
when is_assembly_type = 1 then 'UDT'
when is_table_type = 1 then 'TT'
else 'UDDT'
end as [type],
schema_name(schema_id) as name1,
name as name2,
null as name3,
null as a1,
binary_checksum(system_type_id, schema_id, max_length, precision, scale, is_nullable, is_assembly_type, default_object_id, rule_object_id) as v1,
null as mod
from sys.types
where
is_user_defined = 1

union

select idx.object_id as id,
idx.index_id as id2,
case
when idx.type = 3 then 'XIX'
when idx.type = 4 then 'SIX'
when idx.type = 6 then 'CIX'
else 'IDX'
end as [type],
schema_name(tab.schema_id) as name,
tab.name as name2,
idx.name as name3,
null as a1,
binary_checksum(is_unique, data_space_id, ignore_dup_key, is_primary_key, is_unique_constraint, fill_factor, is_padded, is_disabled, allow_row_locks, allow_page_locks) as v1,
null as mod
from sys.indexes idx
inner join sys.tables tab on idx.object_id = tab.object_id
where
idx.is_primary_key = 0
and idx.name is not null
and idx.is_unique_constraint = 0
and idx.is_hypothetical = 0

union

select stat.object_id as id,
stat.stats_id as id2,
'STAT' as [type],
schema_name(tab.schema_id) as name,
tab.name as name2,
stat.name as name3,
null as a1,
no_recompute as v1,
null as mod
from sys.stats stat
inner join sys.tables tab on stat.object_id = tab.object_id
where
stat.user_created = 1

union

select xml_collection_id as id,
null as id2,
'XSC' as type,
schema_name(schema_id),
name as name2,
null as name3,
null as a1,
null as v1,
modify_date as mod
from sys.xml_schema_collections
where xml_collection_id > 1

union

select
object_id id,
null id2,
'DDT' as type,
name,
null as name2,
null as name3,
null as a1,
null as v1,
modify_date as mod
from sys.triggers
where
parent_class = 0

union

select
database_specification_id id,
null as id2,
'DAS' as type,
name as name1,
null as name2,
null as name3,
null as a1,
null as v1,
modify_date as mod
from sys.database_audit_specifications

union

select
certificate_id id,
null as id2,
'CERT' as type,
name as name1,
null as name2,
null as name3,
principal_id as a1,
binary_checksum(pvt_key_encryption_type, thumbprint) as v1,
null as mod
from sys.certificates

union

select
asymmetric_key_id id,
null as id2,
'ASMK' as type,
name as name1,
null as name2,
null as name3,
principal_id as a1,
null as v1,
null as mod
from sys.asymmetric_keys

union

select
symmetric_key_id id,
null as id2,
case
when name = N'##MS_DatabaseMasterKey##' then 'MK'
else 'SYMK'
end as type,
case
when name = N'##MS_DatabaseMasterKey##' then null
else name
end as name1,
null as name2,
null as name3,
principal_id as a1,
null as v1,
modify_date as mod
from sys.symmetric_keys
where
name = N'##MS_DatabaseMasterKey##'
or name not like N'##%'

union

select
fulltext_catalog_id id,
null as id2,
'FTC' as type,
name as name1,
null as name2,
null as name3,
principal_id as a1,
binary_checksum(is_default, is_accent_sensitivity_on) as v1,
null as mod
from sys.fulltext_catalogs

union

sel

Code Snippets

select object_id as id, 
    null as id2,
    case
        when [type] != 'D ' then [type]
        when parent_object_id != 0 then 'D '
        else 'LD' 
    end as [type],
    schema_name(schema_id) as name1,
    name as name2,
    null as name3,
    null as a1,
    null as v1,
    modify_date as mod
from sys.objects
where 
    type != 'S'
    and is_ms_shipped != 1

union

select principal_id as id, 
    null as id2,
    type, 
    name as name1, 
    null as name2, 
    null as name3,
    null as a1,
    null as v1,
    modify_date as mod
from sys.database_principals

union

select assembly_id as id, 
    null as id2,
    'CLR' as type, 
    name as name1, 
    null as name2, 
    null as name3,
    principal_id as a1,
    null as v1,
    modify_date as mod
from sys.assemblies
where
    is_user_defined =1

union

select schema_id as id, 
    null as id2,
    'SCH' as type, 
    name as name1, 
    null as name2, 
    null as name3,
    principal_id as a1,
    null as v1,
    null as mod
from sys.schemas

union

select user_type_id as id, 
    null as id2,
    case
        when is_assembly_type = 1 then 'UDT'
        when is_table_type = 1 then 'TT'
        else 'UDDT'
    end as [type],
    schema_name(schema_id) as name1,
    name as name2,
    null as name3,
    null as a1,
    binary_checksum(system_type_id, schema_id, max_length, precision, scale, is_nullable, is_assembly_type, default_object_id, rule_object_id) as v1,
    null as mod
from sys.types
where
    is_user_defined = 1

union

select idx.object_id as id,
    idx.index_id as id2,
    case
        when idx.type = 3 then 'XIX'
        when idx.type = 4 then 'SIX'
        when idx.type = 6 then 'CIX'
        else 'IDX' 
    end as [type],
    schema_name(tab.schema_id) as name,
    tab.name as name2,
    idx.name as name3,
    null as a1,
    binary_checksum(is_unique, data_space_id, ignore_dup_key, is_primary_key, is_unique_constraint, fill_factor, is_padded, is_disabled, allow_row_locks, allow_page_locks) as v1,
    null as mod
from sys.indexes idx 
    inner join sys.tables tab on idx.object_id = tab.object_id
where 
    idx.is_primary_key = 0
    and idx.name is not null
    and idx.is_unique_constraint = 0
    and idx.is_hypothetical = 0

union

select stat.object_id as id,
    stat.stats_id as id2,
    'STAT' as [type],
    schema_name(tab.schema_id) as name,
    tab.name as name2,
    stat.name as name3,
    null as a1,
    no_recompute as v1,
    null as mod
from sys.stats stat
    inner join sys.tables tab on stat.object_id = tab.object_id
where 
    stat.user_created = 1

union

select xml_collection_id as id,
    null as id2,
    'XSC' as type,
    schema_name(schema_id),
    name as name2,
    null as name3,
    null as a1,
    null as v1,
    modify_date as mod 
from sys.xml_schema_collections
where xml_collection_id > 1

union

select 
    object_id id,
    null id2,
    'DDT' as type,
    name,
    null as name2,
    null as name3,
    null as a1,
    null as v1,
    
IF Object_ID('admin.blocking_chains', 'V') IS NULL
  BEGIN
    EXEC ('CREATE VIEW admin.blocking_chains AS SELECT NULL As buffer;');
  END
;
GO

ALTER VIEW admin.blocking_chains
  AS
WITH processes AS (
  SELECT s.spid
       , s.blocked As blocking_spid
       , DB_Name(s.dbid) As database_name
       , s.program_name
       , Cast(x.text As varchar(Max)) As definition
       , hostname As host_name
       , loginame As login_name
       , nt_domain
       , nt_username
  FROM   sys.sysprocesses (NOLOCK) As s
   CROSS
    APPLY sys.dm_exec_sql_text(s.sql_handle) As x
  WHERE s.spid > 50
)
, blocking (spid, blocking_spid, blocking_statement, sequence, level, database_name) AS (
  SELECT s.spid
       , s.blocking_spid
       , s.definition
       , Row_Number() OVER (ORDER BY s.spid) As sequence
       , 0 As level
       , s.database_name
  FROM   processes As s
   INNER
    JOIN processes As s1
      ON s1.blocking_spid = s.spid
  WHERE  s.blocking_spid = 0

    UNION ALL

      SELECT r.spid
           , r.blocking_spid
           , r.definition
           , d.sequence
           , d.level + 1
           , r.database_name
      FROM   processes As r
       INNER
        JOIN blocking As d
          ON d.spid = r.blocking_spid
      WHERE  r.blocking_spid > 0
)
, results AS (
  SELECT blocking_spid
       , spid
       , blocking_statement
       , level
       , Min(sequence) As sequence
       , Min(database_name) As database_name
  FROM   blocking
  GROUP
      BY blocking_spid
       , spid
       , blocking_statement
       , level
)
SELECT Cast(CASE WHEN results.blocking_spid = 0 THEN 1 ELSE 0 END As bit) As is_head_of_chain
     , results.sequence
     , results.level
     , results.database_name
     , results.spid
     , results.blocking_spid
     , results.blocking_statement
     , processes.host_name
     , processes.program_name
     , processes.login_name
     , processes.nt_domain
     , processes.nt_username
     , Right('0000' + Cast(results.sequence As varchar(11)), 5) + '-' + Right('0000' + Cast(results.level As varchar(11)), 5) As sort_order
FROM   results
 LEFT
  JOIN processes
    ON processes.spid = results.spid
;

Context

StackExchange Database Administrators Q#104128, answer score: 9

Revisions (0)

No revisions yet.