SQL Server DAC FX SchemaComparison SchemaCompareDatabaseEndpoint失败,没有IntegratedSecuirty

时间:2017-01-17 22:24:13

标签: sql-server

我正在尝试在发布时在目标数据库中查找新创建的表。使用DAC Fx我能够在将新创建的表移动到另一个db之后找到差异并删除表。

我使用IntegratedSecurity开发并测试了代码。在使用SQLServer登录的计算机上启动失败。

我将IntegratedSecurity切换为true的那一刻起作用。这是一个错误吗?

 private void Analyse()
{
            try
            {
                var sourceDacpac = new SchemaCompareDacpacEndpoint(DacPacSrc);                
                var csb = new SqlConnectionStringBuilder(ConnectionString);
                csb.IntegratedSecurity = false;
                var targetDatabase =new SchemaCompareDatabaseEndpoint(csb.ToString());


                var comparison = new SchemaComparison(sourceDacpac, targetDatabase);
                comparison.Options.DropObjectsNotInSource = true;
                var result = comparison.Compare();
                if (result.GetErrors().Any())
                {
                    throw new Exception("Compare failed " + result.GetErrors().FirstOrDefault().Message);
                }

                var delta = new List<string>();
                if (result.Differences != null && result.Differences.Any())
                {
                    var deltaTables = result.Differences.Where(x => x.Name == "Table" && x.UpdateAction == SchemaUpdateAction.Delete);
                    delta = deltaTables.Select(x => x.TargetObject.Name.ToString()).ToList();
                }

                FindingDeltaCompleted?.Invoke(this, new DeltaEventArgs(delta));

            }
            catch (Exception ex)
            {
                Logging.HandleException(ex); 
            }


        }

1 个答案:

答案 0 :(得分:2)

尝试在SQL身份验证连接字符串中设置Persist Security Info=True

SSDT / DAC Fx在HKEY_CURRENT_USER\SOFTWARE\Microsoft\SSDT\ConnectionStrings下的注册表中保存连接字符串。如果未设置Persist Security Info=True,则从注册表加载连接字符串时将无法恢复密码。