Maison  >  Article  >  base de données  >  SQLSERVER数据库管理员的专用连接DAC

SQLSERVER数据库管理员的专用连接DAC

WBOY
WBOYoriginal
2016-06-07 15:44:521370parcourir

SQLSERVER数据库管理员的专用连接DAC DAC: Dedicated Admin Connection 当 SQL Server 因系统资源不足,或其它异常导致无法建立数据库连接时, 可以使用系统预留的 DAC 连接到数据库,进行一些问题诊断和故障排除。DAC只能使用有限的资源。请勿使用DAC运行

SQLSERVER数据库管理员的专用连接DAC

DAC:Dedicated Admin Connection

SQL Server因系统资源不足,或其它异常导致无法建立数据库连接时, 可以使用系统预留的DAC连接到数据库,进行一些问题诊断和故障排除。DAC只能使用有限的资源。请勿使用DAC运行需要消耗大量资源的查询,否则可能发生严重的阻塞。

 

如何启用DAC功能 专用管理员连接功能以及注意事项

1、只有系統管理員(sysadmin)角色相關成員可以使用DAC連接存取SQL Server(Local)本地连接

2、一個執行個體只能存在一個DAC。  

3、使用DAC通常是讓DBA查詢和排解SQL Server問題(當無法正常連接執行個體),

4、好比執行sp_who2、Kill SPID、DBCC SQLPERF、DBCC DROPCLEANBUFFERS …等,使用DAC連接時,切勿執行需耗費大量資源的命令,如DBCC CHECKDB、DBCC SHRINKDATABASE..等

5、使用DAC登录才能修改系统表或者查看系统表,以前SQL2000的时候你可以随便修改系统表,到了SQL2005就开始限制您了

开启DAC的SQL

<span> 1</span> <span>USE</span><span> master        
</span><span> 2</span> <span>GO</span>        
<span> 3</span> sp_configure <span>'</span><span>show advanced options</span><span>'</span>, <span>1</span> 
<span> 4</span> <span>GO</span>    
<span> 5</span> sp_configure <span>'</span><span>remote admin connections</span><span>'</span>, <span>1</span> 
<span> 6</span> <span>GO</span>        
<span> 7</span> <span>RECONFIGURE</span> <span>WITH</span><span> OVERRIDE    
</span><span> 8</span> <span>GO</span>
<span> 9</span> 
<span>10</span> 
<span>11</span> <span>SELECT</span> <span>*</span>  <span>FROM</span> sys.configurations <span>where</span> name <span>=</span> <span>'</span><span>remote admin connections</span><span>'</span>

也可以在外围应用配置器那里开启

SQLSERVER数据库管理员的专用连接DAC

 

命令行下使用DAC登录
sqlcmd加上 /A 选项  专用管理连接
sqlcmd /S  JOE  /E  /A
1>DBCC DROPCLEANBUFFERS
2>GO

 

排错和诊断的SQL

<span>1</span> <span>SELECT</span> <span>*</span> <span>FROM</span><span> sys.dm_tran_locks
</span><span>2</span> <span>SELECT</span> <span>*</span> <span>FROM</span><span> sys.dm_os_memory_cache_counters
</span><span>3</span> <span>SELECT</span> <span>*</span> <span>FROM</span><span> sys.dm_exec_requests 
</span><span>4</span> <span>SELECT</span> <span>*</span> <span>FROM</span> sys.dm_exec_sessions

例如查询 sys.dm_tran_locks 以了解锁定状态

查询 sys.dm_os_memory_cache_counters ,检查缓存数量

查询sys.dm_exec_requests 和 sys.dm_exec_sessions 以了解活动的会话和请求。
避免使用需要消耗大量资源的 DMV(例如,sys.dm_tran_version_store 需要扫描整个版本存储区,并且会导致大量的 I/O)或使用了复杂联接的 DMV

 

在sqlserver management studio中使用DAC连接的时候,要选择新建查询或者数据库引擎查询,不能使用一上来默认的那个登录框进行DAC连接登录,那个

是连接数据库引擎的,如果用DAC连数据库引擎,会报不支持DAC连接。

SQLSERVER数据库管理员的专用连接DAC

SQLSERVER数据库管理员的专用连接DAC

 

 

 

下面说一下DAC侦听的端口号

若要了解 DAC 所侦听的端口号,可以看SQL错误日志
SQL错误日志
消息
Dedicated admin connection support was established for listening remotely on port 1434.

其他有关DAC错误日志的消息:

消息
Could not connect because the maximum number of '1' dedicated administrator connections already exists. Before a new connection can be made, the existing dedicated administrator connection must be dropped, either by logging off or ending the process. [客户端: 127.0.0.1]

消息
Configuration option 'remote admin connections' changed from 1 to 1. Run the RECONFIGURE statement to install

 

DAC的本地连接和远程连接的方式:

如果将 SQL Server 配置为接受远程管理连接,则必须使用显式端口号启动 DAC:

sqlcmd –Stcp:,

sqlcmd /Stcp:192.168.1.100,1434 /U sa /P test

 

 

SQL Server 错误日志列出了 DAC 的端口号,默认情况下为 1434。

如果将 SQL Server 配置为只接受本地 DAC 连接,请使用以下命令和环回适配器进行连接:

sqlcmd –S127.0.0.1,1434

或者

sqlcmd加上 /A 选项  专用管理连接
sqlcmd /S  JOE  /E  /A

或者

SQLSERVER数据库管理员的专用连接DAC

或者

SQLSERVER数据库管理员的专用连接DAC

 

 

总结:经过本人的实验,发现无论你是用sqlcmd或者SSMS,本地连接还是远程连接,都要使用这种方式

sqlcmd –Stcp:,

本地:sqlcmd –S127.0.0.1,1434

远程:sqlcmd /Stcp:192.168.1.100,1434 /U sa /P test

网上有些文章说不用加端口号,启用SQL Browser服务,就可以连接SQLSERVER,实际上不加1434端口号的话,已经不是在使用DAC来

连接SQLSERVER了,不加1434端口号使用的只是普通连接


2013-11-30补充:

反编译了一下DAC的DLL

在下面的公用DLL路径

DAC功能应该就是调用这个路径下的C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.Management.Dac.dll

ILSpy这个工具来反编译,实际上SQLSRVER很多功能组件都是用.NET来编写的

除非一些核心功能组件用C++或者C,你们会发现很多DLL都可以用ILSpy这个.NET反编译工具来反编译

微乳并没有混淆他们的代码,这些如果没有开发文档的话,要理解这些代码的层次结构和意思会比较困难

SQLSERVER数据库管理员的专用连接DAC

 SQLSERVER数据库管理员的专用连接DAC

 

SQLSERVER数据库管理员的专用连接DAC

SQLSERVER数据库管理员的专用连接DAC

 

其中一个类的代码

SQLSERVER数据库管理员的专用连接DACSQLSERVER数据库管理员的专用连接DAC

<span>  1</span> <span>using Microsoft.SqlServer.Management.Common;
</span><span>  2</span> <span>using Microsoft.SqlServer.Management.Smo;
</span><span>  3</span> <span>using Microsoft.SqlServer.Management.SmoMetadataProvider;
</span><span>  4</span> <span>using Microsoft.SqlServer.Management.SqlParser.Common;
</span><span>  5</span> <span>using Microsoft.SqlServer.Management.SqlParser.Metadata;
</span><span>  6</span> <span>using Microsoft.SqlServer.Management.SqlParser.MetadataDifferencer;
</span><span>  7</span> <span>using Microsoft.SqlServer.Management.SqlParser.MetadataServices;
</span><span>  8</span> <span>using System;
</span><span>  9</span> <span>using System.Collections;
</span><span> 10</span> <span>using System.Collections.Generic;
</span><span> 11</span> <span>using System.Globalization;
</span><span> 12</span> <span>using System.IO;
</span><span> 13</span> <span>using System.Linq;
</span><span> 14</span> <span>using System.Runtime.CompilerServices;
</span><span> 15</span> using System.<span>Text</span><span>;
</span><span> 16</span> using System.<span>Text</span><span>.RegularExpressions;
</span><span> 17</span> <span>using System.Xml;
</span><span> 18</span> <span>namespace Microsoft.SqlServer.Management.Dac.UI
</span><span> 19</span> <span>{
</span><span> 20</span> <span>    internal class InternalUIHooks
</span><span> 21</span> <span>    {
</span><span> 22</span> <span>        private static class DifferencerTestUtils
</span><span> 23</span> <span>        {
</span><span> 24</span> <span>            private class DacUtils
</span><span> 25</span> <span>            {
</span><span> 26</span>                 <span>public</span> class MetadataObjectComparer : IComparer<span>IMetadataObject<span>></span>
<span> 27</span> <span>                {
</span><span> 28</span>                     <span>public</span> static InternalUIHooks.DifferencerTestUtils.DacUtils.MetadataObjectComparer Instance <span>=</span><span> new InternalUIHooks.DifferencerTestUtils.DacUtils.MetadataObjectComparer();
</span><span> 29</span>                     <span>public</span> <span>int</span><span> Compare(IMetadataObject x, IMetadataObject y)
</span><span> 30</span> <span>                    {
</span><span> 31</span>                         <span>if</span><span> (object.ReferenceEquals(x, y))
</span><span> 32</span> <span>                        {
</span><span> 33</span>                             <span>return</span> <span>0</span><span>;
</span><span> 34</span> <span>                        }
</span><span> 35</span>                         <span>if</span> (x <span>==</span> <span>null</span><span>)
</span><span> 36</span> <span>                        {
</span><span> 37</span>                             <span>return</span> <span>-</span><span>1</span><span>;
</span><span> 38</span> <span>                        }
</span><span> 39</span>                         <span>if</span> (y <span>==</span> <span>null</span><span>)
</span><span> 40</span> <span>                        {
</span><span> 41</span>                             <span>return</span> <span>1</span><span>;
</span><span> 42</span> <span>                        }
</span><span> 43</span>                         IList<span>IMetadataObject<span>></span> hierarchy <span>=</span><span> InternalUIHooks.DifferencerTestUtils.DacUtils.MetadataObjectComparer.GetHierarchy(x);
</span><span> 44</span>                         IList<span>IMetadataObject<span>></span> hierarchy2 <span>=</span><span> InternalUIHooks.DifferencerTestUtils.DacUtils.MetadataObjectComparer.GetHierarchy(y);
</span><span> 45</span>                         <span>int</span> num <span>=</span> <span>0</span><span>;
</span><span> 46</span>                         <span>while</span> (num <span> hierarchy.<span>Count</span> <span>||</span> num <span> hierarchy2.<span>Count</span><span>)
</span><span> 47</span> <span>                        {
</span><span> 48</span>                             <span>if</span> (num <span>>=</span> hierarchy.<span>Count</span><span>)
</span><span> 49</span> <span>                            {
</span><span> 50</span>                                 <span>return</span> <span>-</span><span>1</span><span>;
</span><span> 51</span> <span>                            }
</span><span> 52</span>                             <span>if</span> (num <span>>=</span> hierarchy2.<span>Count</span><span>)
</span><span> 53</span> <span>                            {
</span><span> 54</span>                                 <span>return</span> <span>1</span><span>;
</span><span> 55</span> <span>                            }
</span><span> 56</span>                             <span>int</span> num2 <span>=</span> hierarchy<span>[</span><span>num</span><span>]</span>.TypeInfo().CompareTo(hierarchy2<span>[</span><span>num</span><span>]</span><span>.TypeInfo());
</span><span> 57</span>                             <span>if</span> (num2 <span>!=</span> <span>0</span><span>)
</span><span> 58</span> <span>                            {
</span><span> 59</span>                                 <span>return</span><span> num2;
</span><span> 60</span> <span>                            }
</span><span> 61</span>                             <span>int</span> num3 <span>=</span> StringComparer.Ordinal.Compare(hierarchy<span>[</span><span>num</span><span>]</span>.Name, hierarchy2<span>[</span><span>num</span><span>]</span><span>.Name);
</span><span> 62</span>                             <span>if</span> (num3 <span>!=</span> <span>0</span><span>)
</span><span> 63</span> <span>                            {
</span><span> 64</span>                                 <span>return</span><span> num3;
</span><span> 65</span> <span>                            }
</span><span> 66</span>                             num<span>++</span><span>;
</span><span> 67</span> <span>                        }
</span><span> 68</span>                         <span>return</span> <span>0</span><span>;
</span><span> 69</span> <span>                    }
</span><span> 70</span>                     private static IList<span>IMetadataObject<span>></span><span> GetHierarchy(IMetadataObject obj)
</span><span> 71</span> <span>                    {
</span><span> 72</span>                         List<span>IMetadataObject<span>></span> list <span>=</span> new List<span>IMetadataObject<span>></span><span>();
</span><span> 73</span>                         <span>for</span> (IMetadataObject metadataObject <span>=</span> obj; metadataObject <span>!=</span> <span>null</span>; metadataObject <span>=</span><span> InternalUIHooks.DifferencerTestUtils.DacUtils.GetParentObjectSafe(metadataObject))
</span><span> 74</span> <span>                        {
</span><span> 75</span>                             list.<span>Add</span><span>(metadataObject);
</span><span> 76</span> <span>                        }
</span><span> 77</span>                         list.<span>Reverse</span><span>();
</span><span> 78</span>                         <span>return</span><span> list;
</span><span> 79</span> <span>                    }
</span><span> 80</span> <span>                }
</span><span> 81</span> <span>                internal static DacType CreateDacFromSql(string sql)
</span><span> 82</span> <span>                {
</span><span> 83</span>                     <span>return</span> InternalUIHooks.DifferencerTestUtils.DacUtils.CreateDacFromSql(sql, new Version("<span>1.1</span>.<span>1.1</span><span>"), string.Empty);
</span><span> 84</span> <span>                }
</span><span> 85</span> <span>                internal static DacType CreateDacFromSql(string sql, Version version, string description)
</span><span> 86</span> <span>                {
</span><span> 87</span>                     DacCompilationUnit dacCompilationUnit <span>=</span><span> new DacCompilationUnit("Dac", version, "SQL_Latin1_General_CP1_CI_AS");
</span><span> 88</span>                     dacCompilationUnit.Description <span>=</span><span> description;
</span><span> 89</span> <span>                    dacCompilationUnit.AddTSqlSourceFile("input.sql", sql);
</span><span> 90</span>                     DacCompilationResult dacCompilationResult <span>=</span><span> dacCompilationUnit.Compile();
</span><span> 91</span>                     List<span>DacCompilationError<span>></span> list <span>=</span> new List<span>DacCompilationError<span>></span><span>(dacCompilationResult.Errors);
</span><span> 92</span>                     <span>if</span> (list.<span>Count</span> <span>!=</span> <span>0</span><span>)
</span><span> 93</span> <span>                    {
</span><span> 94</span> <span>                        InternalUIHooks.DifferencerTestUtils.DacUtils.PrintCompilationResultErrors(dacCompilationResult);
</span><span> 95</span> <span>                    }
</span><span> 96</span>                     <span>return</span><span> InternalUIHooks.DifferencerTestUtils.DacUtils.NormalizeDacType(dacCompilationResult.DacType);
</span><span> 97</span> <span>                }
</span><span> 98</span> <span>                private static DacType NormalizeDacType(DacType dacType)
</span><span> 99</span> <span>                {
</span><span>100</span> <span>                    DacType result;
</span><span>101</span>                     using (MemoryStream memoryStream <span>=</span><span> new MemoryStream())
</span><span>102</span> <span>                    {
</span><span>103</span>                         DacType.<span>Save</span><span>(dacType, memoryStream);
</span><span>104</span>                         memoryStream.Seek(0L, SeekOrigin.<span>Begin</span><span>);
</span><span>105</span>                         result <span>=</span> DacType.<span>Load</span><span>(memoryStream);
</span><span>106</span> <span>                    }
</span><span>107</span>                     <span>return</span><span> result;
</span><span>108</span> <span>                }
</span><span>109</span> <span>                private static void PrintCompilationResultErrors(DacCompilationResult result)
</span><span>110</span> <span>                {
</span><span>111</span>                     List<span>DacCompilationError<span>></span> list <span>=</span> new List<span>DacCompilationError<span>></span><span>(result.Errors);
</span><span>112</span>                     Console.WriteLine("Compilation Result Errors (" <span>+</span> list.<span>Count</span> <span>+</span><span> ")");
</span><span>113</span>                     foreach (DacCompilationError <span>current</span> <span>in</span><span> list)
</span><span>114</span> <span>                    {
</span><span>115</span>                         Console.WriteLine("\t<span>-</span> {<span>0</span>}{<span>1</span>}: " <span>+</span> <span>current</span>.ToString(), <span>current</span>.IsWarning ? "Warning" : "Error", (<span>current</span>.SourceInfo <span>!=</span> <span>null</span>) ? (" " <span>+</span> InternalUIHooks.DifferencerTestUtils.DacUtils.GetLocationString(<span>current</span><span>.SourceInfo)) : "");
</span><span>116</span> <span>                    }
</span><span>117</span> <span>                    Console.WriteLine();
</span><span>118</span> <span>                }
</span><span>119</span> <span>                private static string GetLocationString(SourceInfo sourceInfo)
</span><span>120</span> <span>                {
</span><span>121</span>                     <span>return</span> string.Concat(new object<span>[]</span>
<span>122</span> <span>                    {
</span><span>123</span> <span>                        sourceInfo.Filename, 
</span><span>124</span> <span>                        ":", 
</span><span>125</span> <span>                        sourceInfo.Start.LineNumber, 
</span><span>126</span> <span>                        ",", 
</span><span>127</span> <span>                        sourceInfo.Start.ColumnNumber
</span><span>128</span> <span>                    });
</span><span>129</span> <span>                }
</span><span>130</span>                 <span>public</span><span> static DacType CreateDacFromFile(string fileName)
</span><span>131</span> <span>                {
</span><span>132</span>                     string sql <span>=</span> <span>File</span><span>.ReadAllText(fileName);
</span><span>133</span>                     <span>return</span><span> InternalUIHooks.DifferencerTestUtils.DacUtils.CreateDacFromSql(sql);
</span><span>134</span> <span>                }
</span><span>135</span>                 <span>public</span><span> static DacType CreateDacFromFile(string fileName, Version version, string description)
</span><span>136</span> <span>                {
</span><span>137</span>                     string sql <span>=</span> <span>File</span><span>.ReadAllText(fileName);
</span><span>138</span>                     <span>return</span><span> InternalUIHooks.DifferencerTestUtils.DacUtils.CreateDacFromSql(sql, version, description);
</span><span>139</span> <span>                }
</span><span>140</span>                 <span>public</span><span> static string GetMetadataObjectIdString(IMetadataObject obj)
</span><span>141</span> <span>                {
</span><span>142</span>                     List<span>string<span>></span> list <span>=</span> new List<span>string<span>></span><span>();
</span><span>143</span>                     IMetadataObject metadataObject <span>=</span><span> obj;
</span><span>144</span>                     <span>while</span><span> (true)
</span><span>145</span> <span>                    {
</span><span>146</span>                         TypeInfo typeInfo <span>=</span><span> metadataObject.TypeInfo();
</span><span>147</span>                         string <span>text</span> <span>=</span> typeInfo.Name.<span>Substring</span>(<span>1</span><span>);
</span><span>148</span>                         string item <span>=</span> string.Format(CultureInfo.InvariantCulture, "{<span>0</span>}{<span>1</span>}", new object<span>[]</span>
<span>149</span> <span>                        {
</span><span>150</span>                             <span>text</span><span>, 
</span><span>151</span>                             (!(metadataObject <span>is</span> IServer)) ? ("<span>[</span><span>" + metadataObject.Name.Replace("</span><span>]</span>", "]]") <span>+</span><span> "]") : string.Empty
</span><span>152</span> <span>                        });
</span><span>153</span>                         list.<span>Add</span><span>(item);
</span><span>154</span>                         <span>if</span> (metadataObject <span>is</span><span> IServer)
</span><span>155</span> <span>                        {
</span><span>156</span>                             <span>break</span><span>;
</span><span>157</span> <span>                        }
</span><span>158</span>                         metadataObject <span>=</span><span> InternalUIHooks.DifferencerTestUtils.DacUtils.GetParentObject(metadataObject);
</span><span>159</span> <span>                    }
</span><span>160</span>                     list.<span>Reverse</span><span>();
</span><span>161</span>                     <span>return</span> string.<span>Join</span>("<span>/</span><span>", list.ToArray());
</span><span>162</span> <span>                }
</span><span>163</span>                 <span>public</span><span> static string GetMetadataObjectTypeString(IMetadataObject obj)
</span><span>164</span> <span>                {
</span><span>165</span>                     <span>return</span> obj.TypeInfo().Name.<span>Substring</span>(<span>1</span><span>);
</span><span>166</span> <span>                }
</span><span>167</span>                 <span>public</span><span> static IMetadataObject GetParentObject(IMetadataObject obj)
</span><span>168</span> <span>                {
</span><span>169</span>                     MetadataTypeInfo metadataTypeInfo <span>=</span><span> obj.TypeInfo();
</span><span>170</span>                     MetadataPropertyInfo parentProperty <span>=</span><span> metadataTypeInfo.ParentProperty;
</span><span>171</span>                     object propertyValue <span>=</span><span> MetadataUtils.GetPropertyValue(obj, metadataTypeInfo, parentProperty);
</span><span>172</span>                     <span>return</span><span> (IMetadataObject)propertyValue;
</span><span>173</span> <span>                }
</span><span>174</span>                 <span>public</span><span> static IMetadataObject GetParentObjectSafe(IMetadataObject obj)
</span><span>175</span> <span>                {
</span><span>176</span>                     MetadataTypeInfo metadataTypeInfo <span>=</span><span> obj.TypeInfo();
</span><span>177</span>                     MetadataPropertyInfo parentProperty <span>=</span><span> metadataTypeInfo.ParentProperty;
</span><span>178</span>                     <span>if</span> (parentProperty <span>==</span> <span>null</span><span>)
</span><span>179</span> <span>                    {
</span><span>180</span>                         <span>return</span> <span>null</span><span>;
</span><span>181</span> <span>                    }
</span><span>182</span>                     object propertyValue <span>=</span><span> MetadataUtils.GetPropertyValue(obj, metadataTypeInfo, parentProperty);
</span><span>183</span>                     <span>return</span><span> (IMetadataObject)propertyValue;
</span><span>184</span> <span>                }
</span><span>185</span>                 <span>public</span><span> static void WriteObject(XmlWriter writer, object value, bool writeDefinition)
</span><span>186</span> <span>                {
</span><span>187</span>                     Type type <span>=</span> (value <span>!=</span> <span>null</span>) ? value.GetType() : <span>null</span><span>;
</span><span>188</span>                     <span>if</span> (value <span>==</span> <span>null</span><span>)
</span><span>189</span> <span>                    {
</span><span>190</span>                         writer.WriteAttributeString("<span>isNull</span><span>", true.ToString());
</span><span>191</span>                         <span>return</span><span>;
</span><span>192</span> <span>                    }
</span><span>193</span>                     <span>if</span> (type.IsPrimitive <span>||</span> type.IsEnum <span>||</span> type <span>==</span><span> typeof(string))
</span><span>194</span> <span>                    {
</span><span>195</span> <span>                        writer.WriteString(value.ToString());
</span><span>196</span>                         <span>return</span><span>;
</span><span>197</span> <span>                    }
</span><span>198</span>                     <span>if</span> (type <span>==</span><span> typeof(IdentityColumnInfo))
</span><span>199</span> <span>                    {
</span><span>200</span> <span>                        writer.WriteStartElement("Increment");
</span><span>201</span> <span>                        InternalUIHooks.DifferencerTestUtils.DacUtils.WriteObject(writer, ((IdentityColumnInfo)value).Increment, true);
</span><span>202</span> <span>                        writer.WriteEndElement();
</span><span>203</span> <span>                        writer.WriteStartElement("Seed");
</span><span>204</span> <span>                        InternalUIHooks.DifferencerTestUtils.DacUtils.WriteObject(writer, ((IdentityColumnInfo)value).Seed, true);
</span><span>205</span> <span>                        writer.WriteEndElement();
</span><span>206</span>                         <span>return</span><span>;
</span><span>207</span> <span>                    }
</span><span>208</span>                     <span>if</span> (type <span>==</span><span> typeof(ComputedColumnInfo))
</span><span>209</span> <span>                    {
</span><span>210</span> <span>                        writer.WriteStartElement("IsPersisted");
</span><span>211</span> <span>                        InternalUIHooks.DifferencerTestUtils.DacUtils.WriteObject(writer, ((ComputedColumnInfo)value).IsPersisted, true);
</span><span>212</span> <span>                        writer.WriteEndElement();
</span><span>213</span>                         writer.WriteStartElement("<span>Text</span><span>");
</span><span>214</span>                         InternalUIHooks.DifferencerTestUtils.DacUtils.WriteObject(writer, ((ComputedColumnInfo)value).<span>Text</span><span>, true);
</span><span>215</span> <span>                        writer.WriteEndElement();
</span><span>216</span>                         <span>return</span><span>;
</span><span>217</span> <span>                    }
</span><span>218</span>                     <span>if</span> (type <span>==</span><span> typeof(DataTypeSpec))
</span><span>219</span> <span>                    {
</span><span>220</span> <span>                        writer.WriteString(((DataTypeSpec)value).SqlDataType.ToString());
</span><span>221</span>                         <span>return</span><span>;
</span><span>222</span> <span>                    }
</span><span>223</span>                     <span>if</span> (type <span>==</span><span> typeof(CollationInfo))
</span><span>224</span> <span>                    {
</span><span>225</span> <span>                        writer.WriteStartElement("CollationInfo");
</span><span>226</span> <span>                        InternalUIHooks.DifferencerTestUtils.DacUtils.WriteObject(writer, ((CollationInfo)value).Name, true);
</span><span>227</span> <span>                        writer.WriteEndElement();
</span><span>228</span>                         <span>return</span><span>;
</span><span>229</span> <span>                    }
</span><span>230</span>                     <span>if</span> (value <span>is</span><span> ISystemClrDataType)
</span><span>231</span> <span>                    {
</span><span>232</span> <span>                        writer.WriteStartElement("ISystemClrDataType");
</span><span>233</span> <span>                        InternalUIHooks.DifferencerTestUtils.DacUtils.WriteObject(writer, ((ISystemClrDataType)value).Name, true);
</span><span>234</span> <span>                        writer.WriteEndElement();
</span><span>235</span>                         <span>return</span><span>;
</span><span>236</span> <span>                    }
</span><span>237</span>                     <span>if</span> (value <span>is</span><span> IMetadataObject)
</span><span>238</span> <span>                    {
</span><span>239</span>                         IMetadataObject obj <span>=</span><span> (IMetadataObject)value;
</span><span>240</span>                         MetadataTypeInfo metadataTypeInfo <span>=</span><span> obj.TypeInfo();
</span><span>241</span>                         <span>if</span> (metadataTypeInfo.IsValue <span>||</span> (metadataTypeInfo.IsReference <span>&&</span><span> writeDefinition))
</span><span>242</span> <span>                        {
</span><span>243</span> <span>                            writer.WriteStartElement(InternalUIHooks.DifferencerTestUtils.DacUtils.GetMetadataObjectTypeString(obj));
</span><span>244</span>                             foreach (MetadataPropertyInfo <span>current</span> <span>in</span><span> metadataTypeInfo.InstanceProperties)
</span><span>245</span> <span>                            {
</span><span>246</span>                                 object propertyValue <span>=</span> MetadataUtils.GetPropertyValue(obj, metadataTypeInfo, <span>current</span><span>);
</span><span>247</span>                                 writer.WriteStartElement(<span>current</span><span>.Name);
</span><span>248</span>                                 InternalUIHooks.DifferencerTestUtils.DacUtils.WriteObject(writer, propertyValue, writeDefinition <span>&&</span> <span>current</span>.PropertyType <span>==</span><span> PropertyType.Child);
</span><span>249</span> <span>                                writer.WriteEndElement();
</span><span>250</span> <span>                            }
</span><span>251</span> <span>                            writer.WriteEndElement();
</span><span>252</span>                             <span>return</span><span>;
</span><span>253</span> <span>                        }
</span><span>254</span>                         <span>if</span><span> (metadataTypeInfo.IsReference)
</span><span>255</span> <span>                        {
</span><span>256</span> <span>                            writer.WriteAttributeString("id", InternalUIHooks.DifferencerTestUtils.DacUtils.GetMetadataObjectIdString(obj));
</span><span>257</span>                             <span>return</span><span>;
</span><span>258</span> <span>                        }
</span><span>259</span> <span>                    }
</span><span>260</span>                     <span>else</span>
<span>261</span> <span>                    {
</span><span>262</span>                         <span>if</span> (value <span>is</span><span> IEnumerable)
</span><span>263</span> <span>                        {
</span><span>264</span>                             foreach (object current2 <span>in</span><span> (IEnumerable)value)
</span><span>265</span> <span>                            {
</span><span>266</span>                                 string localName <span>=</span> (current2 <span>is</span><span> IMetadataObject) ? InternalUIHooks.DifferencerTestUtils.DacUtils.GetMetadataObjectTypeString((IMetadataObject)current2) : "Item";
</span><span>267</span> <span>                                writer.WriteStartElement(localName);
</span><span>268</span> <span>                                InternalUIHooks.DifferencerTestUtils.DacUtils.WriteObject(writer, current2, writeDefinition);
</span><span>269</span> <span>                                writer.WriteEndElement();
</span><span>270</span> <span>                            }
</span><span>271</span> <span>                        }
</span><span>272</span> <span>                    }
</span><span>273</span> <span>                }
</span><span>274</span> <span>            }
</span><span>275</span>             <span>public</span><span> static void WriteChangeResult(XmlWriter writer, ChangeResult changeResult)
</span><span>276</span> <span>            {
</span><span>277</span> <span>                writer.WriteStartElement("ChangeResult");
</span><span>278</span> <span>                writer.WriteStartElement("CreatedObjects");
</span><span>279</span> <span>                InternalUIHooks.DifferencerTestUtils.WriteObjectRefs(writer, changeResult.CreatedObjects);
</span><span>280</span> <span>                writer.WriteEndElement();
</span><span>281</span> <span>                writer.WriteStartElement("DeletedObjects");
</span><span>282</span> <span>                InternalUIHooks.DifferencerTestUtils.WriteObjectRefs(writer, changeResult.DeletedObjects);
</span><span>283</span> <span>                writer.WriteEndElement();
</span><span>284</span> <span>                writer.WriteStartElement("ModifiedObjects");
</span><span>285</span>                 InternalUIHooks.DifferencerTestUtils.WriteModifiedObjects(writer, changeResult.SourceModifiedObjects.<span>Values</span><span>);
</span><span>286</span> <span>                writer.WriteEndElement();
</span><span>287</span> <span>                writer.WriteEndElement();
</span><span>288</span> <span>            }
</span><span>289</span>             <span>public</span> static void WriteModifiedObjects(XmlWriter writer, IEnumerable<span>ObjectDifference<span>></span><span> objectDifferenceCollection)
</span><span>290</span> <span>            {
</span><span>291</span>                 List<span>ObjectDifference<span>></span> list <span>=</span> objectDifferenceCollection.ToList<span>ObjectDifference<span>></span><span>();
</span><span>292</span>                 list.Sort((ObjectDifference x, ObjectDifference y) <span>=></span> InternalUIHooks.DifferencerTestUtils.DacUtils.MetadataObjectComparer.Instance.Compare(x.ChangedObjectSource, y.ChangedObjectSource) <span>*</span> <span>2</span> <span>+</span><span> InternalUIHooks.DifferencerTestUtils.DacUtils.MetadataObjectComparer.Instance.Compare(x.ChangedObjectTarget, y.ChangedObjectTarget));
</span><span>293</span> <span>                list.ForEach(delegate(ObjectDifference diff)
</span><span>294</span> <span>                {
</span><span>295</span> <span>                    InternalUIHooks.DifferencerTestUtils.WriteObjectDifference(writer, diff);
</span><span>296</span> <span>                }
</span><span>297</span> <span>                );
</span><span>298</span> <span>            }
</span><span>299</span>             <span>public</span><span> static void WriteObjectDifference(XmlWriter writer, ObjectDifference objectDifference)
</span><span>300</span> <span>            {
</span><span>301</span> <span>                writer.WriteStartElement(InternalUIHooks.DifferencerTestUtils.DacUtils.GetMetadataObjectTypeString(objectDifference.ChangedObjectSource));
</span><span>302</span> <span>                writer.WriteStartElement("ChangedObjectSource");
</span><span>303</span> <span>                writer.WriteAttributeString("Id", InternalUIHooks.DifferencerTestUtils.DacUtils.GetMetadataObjectIdString(objectDifference.ChangedObjectSource));
</span><span>304</span> <span>                writer.WriteEndElement();
</span><span>305</span> <span>                writer.WriteStartElement("ChangedObjectTarget");
</span><span>306</span> <span>                writer.WriteAttributeString("Id", InternalUIHooks.DifferencerTestUtils.DacUtils.GetMetadataObjectIdString(objectDifference.ChangedObjectTarget));
</span><span>307</span> <span>                writer.WriteEndElement();
</span><span>308</span> <span>                writer.WriteStartElement("Properties");
</span><span>309</span>                 List<span>PropertyDifference<span>></span> list <span>=</span><span> (
</span><span>310</span>                     <span>from</span> p <span>in</span> objectDifference.PropertyDifferences.<span>Values</span>
<span>311</span> <span>                    orderby p.Name
</span><span>312</span>                     <span>select</span> p).ToList<span>PropertyDifference<span>></span><span>();
</span><span>313</span> <span>                list.ForEach(delegate(PropertyDifference p)
</span><span>314</span> <span>                {
</span><span>315</span> <span>                    InternalUIHooks.DifferencerTestUtils.WritePropertyDifference(writer, p);
</span><span>316</span> <span>                }
</span><span>317</span> <span>                );
</span><span>318</span> <span>                writer.WriteEndElement();
</span><span>319</span> <span>                writer.WriteEndElement();
</span><span>320</span> <span>            }
</span><span>321</span>             <span>public</span><span> static void WritePropertyDifference(XmlWriter writer, PropertyDifference propertyDifference)
</span><span>322</span> <span>            {
</span><span>323</span> <span>                writer.WriteStartElement(propertyDifference.Name);
</span><span>324</span>                 <span>if</span> (propertyDifference <span>is</span><span> OrderedCollectionDifference)
</span><span>325</span> <span>                {
</span><span>326</span>                     OrderedCollectionDifference orderedCollectionDifference <span>=</span> propertyDifference <span>as</span><span> OrderedCollectionDifference;
</span><span>327</span>                     using (IEnumerator<span>OrderedScalarDifference<span>></span> enumerator <span>=</span><span> orderedCollectionDifference.OrderDifferences.GetEnumerator())
</span><span>328</span> <span>                    {
</span><span>329</span>                         <span>while</span><span> (enumerator.MoveNext())
</span><span>330</span> <span>                        {
</span><span>331</span>                             OrderedScalarDifference <span>current</span> <span>=</span> enumerator.<span>Current</span><span>;
</span><span>332</span>                             writer.WriteStartElement(InternalUIHooks.DifferencerTestUtils.DacUtils.GetMetadataObjectTypeString((IMetadataObject)<span>current</span><span>.SourceValue));
</span><span>333</span>                             writer.WriteAttributeString("sourceIndex", <span>current</span><span>.SourceIndex.ToString(CultureInfo.InvariantCulture));
</span><span>334</span>                             writer.WriteAttributeString("targetIndex", <span>current</span><span>.TargetIndex.ToString(CultureInfo.InvariantCulture));
</span><span>335</span> <span>                            writer.WriteStartElement("SourceValue");
</span><span>336</span>                             InternalUIHooks.DifferencerTestUtils.DacUtils.WriteObject(writer, <span>current</span><span>.SourceValue, false);
</span><span>337</span> <span>                            writer.WriteEndElement();
</span><span>338</span> <span>                            writer.WriteStartElement("TargetValue");
</span><span>339</span>                             InternalUIHooks.DifferencerTestUtils.DacUtils.WriteObject(writer, <span>current</span><span>.TargetValue, false);
</span><span>340</span> <span>                            writer.WriteEndElement();
</span><span>341</span> <span>                            writer.WriteEndElement();
</span><span>342</span> <span>                        }
</span><span>343</span>                         <span>goto</span><span> IL_12E;
</span><span>344</span> <span>                    }
</span><span>345</span> <span>                }
</span><span>346</span>                 <span>if</span> (propertyDifference <span>is</span><span> ScalarDifference)
</span><span>347</span> <span>                {
</span><span>348</span>                     ScalarDifference scalarDifference <span>=</span> propertyDifference <span>as</span><span> ScalarDifference;
</span><span>349</span> <span>                    writer.WriteStartElement("SourceValue");
</span><span>350</span> <span>                    InternalUIHooks.DifferencerTestUtils.DacUtils.WriteObject(writer, scalarDifference.SourceValue, false);
</span><span>351</span> <span>                    writer.WriteEndElement();
</span><span>352</span> <span>                    writer.WriteStartElement("TargetValue");
</span><span>353</span> <span>                    InternalUIHooks.DifferencerTestUtils.DacUtils.WriteObject(writer, scalarDifference.TargetValue, false);
</span><span>354</span> <span>                    writer.WriteEndElement();
</span><span>355</span> <span>                }
</span><span>356</span> <span>                IL_12E:
</span><span>357</span> <span>                writer.WriteEndElement();
</span><span>358</span> <span>            }
</span><span>359</span>             <span>public</span> static void WriteObjectRefs(XmlWriter writer, IEnumerable<span>IMetadataObject<span>></span><span> objectCollection)
</span><span>360</span> <span>            {
</span><span>361</span>                 List<span>IMetadataObject<span>></span> list <span>=</span> objectCollection.ToList<span>IMetadataObject<span>></span><span>();
</span><span>362</span> <span>                list.Sort(InternalUIHooks.DifferencerTestUtils.DacUtils.MetadataObjectComparer.Instance);
</span><span>363</span>                 foreach (IMetadataObject <span>current</span> <span>in</span><span> list)
</span><span>364</span> <span>                {
</span><span>365</span>                     writer.WriteStartElement(InternalUIHooks.DifferencerTestUtils.DacUtils.GetMetadataObjectTypeString(<span>current</span><span>));
</span><span>366</span>                     InternalUIHooks.DifferencerTestUtils.DacUtils.WriteObject(writer, <span>current</span><span>, false);
</span><span>367</span> <span>                    writer.WriteEndElement();
</span><span>368</span> <span>                }
</span><span>369</span> <span>            }
</span><span>370</span>             <span>public</span><span> static bool IsChangeResultDrift(ChangeResult changeResult)
</span><span>371</span> <span>            {
</span><span>372</span>                 bool flag <span>=</span> changeResult.CreatedObjects.<span>Count</span><span>IMetadataObject<span>></span>() <span>!=</span> <span>0</span> <span>||</span> changeResult.DeletedObjects.<span>Count</span><span>IMetadataObject<span>></span>() <span>!=</span> <span>0</span><span>;
</span><span>373</span>                 foreach (ObjectDifference <span>current</span> <span>in</span> changeResult.SourceModifiedObjects.<span>Values</span><span>)
</span><span>374</span> <span>                {
</span><span>375</span>                     flag <span>=</span> (!(<span>current</span>.ChangedObjectSource <span>is</span> IConstraint) <span>||</span> (flag <span>|</span> InternalUIHooks.DifferencerTestUtils.IsConstraintDifferenceDrift(<span>current</span><span>)));
</span><span>376</span> <span>                }
</span><span>377</span>                 <span>return</span><span> flag;
</span><span>378</span> <span>            }
</span><span>379</span> <span>            private static bool IsConstraintDifferenceDrift(ObjectDifference objectDifference)
</span><span>380</span> <span>            {
</span><span>381</span>                 bool result <span>=</span><span> false;
</span><span>382</span>                 foreach (PropertyDifference <span>current</span> <span>in</span> objectDifference.PropertyDifferences.<span>Values</span><span>)
</span><span>383</span> <span>                {
</span><span>384</span>                     <span>if</span> (<span>current</span>.Name <span>==</span><span> "IsChecked")
</span><span>385</span> <span>                    {
</span><span>386</span>                         <span>if</span> (!InternalUIHooks.DifferencerTestUtils.IsNotForReplicationConstraint((IConstraint)objectDifference.ChangedObjectSource) <span>&&</span><span> !InternalUIHooks.DifferencerTestUtils.IsNotForReplicationConstraint((IConstraint)objectDifference.ChangedObjectTarget))
</span><span>387</span> <span>                        {
</span><span>388</span>                             result <span>=</span><span> true;
</span><span>389</span> <span>                        }
</span><span>390</span> <span>                    }
</span><span>391</span>                     <span>else</span>
<span>392</span> <span>                    {
</span><span>393</span>                         result <span>=</span><span> true;
</span><span>394</span> <span>                    }
</span><span>395</span> <span>                }
</span><span>396</span>                 <span>return</span><span> result;
</span><span>397</span> <span>            }
</span><span>398</span>             private static bool IsNotForReplicationConstraint(IConstraint <span>constraint</span><span>)
</span><span>399</span> <span>            {
</span><span>400</span> <span>                bool result;
</span><span>401</span>                 switch (<span>constraint</span><span>.Type)
</span><span>402</span> <span>                {
</span><span>403</span>                     <span>case</span> ConstraintType.<span>Check</span><span>:
</span><span>404</span> <span>                    {
</span><span>405</span>                         result <span>=</span> ((ICheckConstraint)<span>constraint</span><span>).NotForReplication;
</span><span>406</span>                         <span>break</span><span>;
</span><span>407</span> <span>                    }
</span><span>408</span>                     <span>case</span><span> ConstraintType.ForeignKey:
</span><span>409</span> <span>                    {
</span><span>410</span>                         result <span>=</span> ((IForeignKeyConstraint)<span>constraint</span><span>).NotForReplication;
</span><span>411</span>                         <span>break</span><span>;
</span><span>412</span> <span>                    }
</span><span>413</span>                     <span>case</span><span> ConstraintType.PrimaryKey:
</span><span>414</span>                     <span>case</span> ConstraintType.<span>Unique</span><span>:
</span><span>415</span> <span>                    {
</span><span>416</span>                         result <span>=</span><span> false;
</span><span>417</span>                         <span>break</span><span>;
</span><span>418</span> <span>                    }
</span><span>419</span>                     <span>default</span><span>:
</span><span>420</span> <span>                    {
</span><span>421</span>                         result <span>=</span><span> false;
</span><span>422</span>                         <span>break</span><span>;
</span><span>423</span> <span>                    }
</span><span>424</span> <span>                }
</span><span>425</span>                 <span>return</span><span> result;
</span><span>426</span> <span>            }
</span><span>427</span> <span>        }
</span><span>428</span>         <span>public</span> const string DacTypeName <span>=</span><span> "Dac";
</span><span>429</span>         <span>public</span> const string DefaultCollation <span>=</span><span> "SQL_Latin1_General_CP1_CI_AS";
</span><span>430</span>         <span>public</span><span> event TextUpdateHandler ScriptUpdate
</span><span>431</span> <span>        {
</span><span>432</span>             <span>[</span><span>MethodImpl(MethodImplOptions.Synchronized)</span><span>]</span>
<span>433</span>             <span>add</span>
<span>434</span> <span>            {
</span><span>435</span>                 this.ScriptUpdate <span>=</span><span> (TextUpdateHandler)Delegate.Combine(this.ScriptUpdate, value);
</span><span>436</span> <span>            }
</span><span>437</span>             <span>[</span><span>MethodImpl(MethodImplOptions.Synchronized)</span><span>]</span>
<span>438</span> <span>            remove
</span><span>439</span> <span>            {
</span><span>440</span>                 this.ScriptUpdate <span>=</span><span> (TextUpdateHandler)Delegate.Remove(this.ScriptUpdate, value);
</span><span>441</span> <span>            }
</span><span>442</span> <span>        }
</span><span>443</span>         <span>public</span><span> event TextUpdateHandler ModelUpdate
</span><span>444</span> <span>        {
</span><span>445</span>             <span>[</span><span>MethodImpl(MethodImplOptions.Synchronized)</span><span>]</span>
<span>446</span>             <span>add</span>
<span>447</span> <span>            {
</span><span>448</span>                 this.ModelUpdate <span>=</span><span> (TextUpdateHandler)Delegate.Combine(this.ModelUpdate, value);
</span><span>449</span> <span>            }
</span><span>450</span>             <span>[</span><span>MethodImpl(MethodImplOptions.Synchronized)</span><span>]</span>
<span>451</span> <span>            remove
</span><span>452</span> <span>            {
</span><span>453</span>                 this.ModelUpdate <span>=</span><span> (TextUpdateHandler)Delegate.Remove(this.ModelUpdate, value);
</span><span>454</span> <span>            }
</span><span>455</span> <span>        }
</span><span>456</span>         <span>public</span><span> event TextUpdateHandler ActionUpdate
</span><span>457</span> <span>        {
</span><span>458</span>             <span>[</span><span>MethodImpl(MethodImplOptions.Synchronized)</span><span>]</span>
<span>459</span>             <span>add</span>
<span>460</span> <span>            {
</span><span>461</span>                 this.ActionUpdate <span>=</span><span> (TextUpdateHandler)Delegate.Combine(this.ActionUpdate, value);
</span><span>462</span> <span>            }
</span><span>463</span>             <span>[</span><span>MethodImpl(MethodImplOptions.Synchronized)</span><span>]</span>
<span>464</span> <span>            remove
</span><span>465</span> <span>            {
</span><span>466</span>                 this.ActionUpdate <span>=</span><span> (TextUpdateHandler)Delegate.Remove(this.ActionUpdate, value);
</span><span>467</span> <span>            }
</span><span>468</span> <span>        }
</span><span>469</span>         <span>public</span><span> DacType CreateDacFromSql(string sql)
</span><span>470</span> <span>        {
</span><span>471</span>             <span>return</span> this.CreateDacFromSql(sql, new Version("<span>1.1</span>.<span>1.1</span><span>"), string.Empty);
</span><span>472</span> <span>        }
</span><span>473</span>         <span>public</span><span> DacType CreateDacFromSql(string sql, Version version, string description)
</span><span>474</span> <span>        {
</span><span>475</span>             DacCompilationUnit dacCompilationUnit <span>=</span><span> new DacCompilationUnit("Dac", version, "SQL_Latin1_General_CP1_CI_AS");
</span><span>476</span>             dacCompilationUnit.Description <span>=</span><span> description;
</span><span>477</span> <span>            dacCompilationUnit.AddTSqlSourceFile("input.sql", sql);
</span><span>478</span>             DacCompilationResult dacCompilationResult <span>=</span><span> dacCompilationUnit.Compile();
</span><span>479</span>             List<span>DacCompilationError<span>></span> list <span>=</span> new List<span>DacCompilationError<span>></span><span>(dacCompilationResult.Errors);
</span><span>480</span>             <span>if</span> (list.<span>Count</span> <span>!=</span> <span>0</span><span>)
</span><span>481</span> <span>            {
</span><span>482</span>                 StringBuilder stringBuilder <span>=</span><span> new StringBuilder();
</span><span>483</span>                 stringBuilder.Append("<span>***</span>COMPILE ERROR<span>***</span><span>");
</span><span>484</span> <span>                stringBuilder.Append(Environment.NewLine);
</span><span>485</span>                 foreach (DacCompilationError <span>current</span> <span>in</span><span> list)
</span><span>486</span> <span>                {
</span><span>487</span>                     stringBuilder.Append(<span>current</span><span>.Message);
</span><span>488</span> <span>                    stringBuilder.Append(Environment.NewLine);
</span><span>489</span> <span>                }
</span><span>490</span> <span>                this.OnScriptUpdate(stringBuilder.ToString());
</span><span>491</span>                 <span>return</span> <span>null</span><span>;
</span><span>492</span> <span>            }
</span><span>493</span>             <span>return</span><span> this.NormalizeDacType(dacCompilationResult.DacType);
</span><span>494</span> <span>        }
</span><span>495</span>         <span>public</span><span> void CompareSQLScripts(string sourceSQL, string targetSQL, bool isAzure)
</span><span>496</span> <span>        {
</span><span>497</span> <span>            this.OnActionUpdate("Building Source SQL DAC");
</span><span>498</span>             DacType dacType <span>=</span> this.CreateDacFromSql(sourceSQL, new Version("<span>1.1</span>.<span>1.1</span><span>"), "V1");
</span><span>499</span> <span>            this.OnActionUpdate("Building Target SQL DAC");
</span><span>500</span>             DacType dacType2 <span>=</span> this.CreateDacFromSql(targetSQL, new Version("<span>2.2</span>.<span>2.2</span><span>"), "V2");
</span><span>501</span> <span>            this.OnActionUpdate("Preparing Incremental Upgrade Script");
</span><span>502</span>             PrepareIncrementalUpgradeScriptStep prepareIncrementalUpgradeScriptStep <span>=</span><span> new PrepareIncrementalUpgradeScriptStep(dacType.Definition, "Dac", dacType2.Definition, "Dac", this.GetDefaultDifferencerFilter(), isAzure ? ScriptTarget.SqlAzure : ScriptTarget.Sql100, false);
</span><span>503</span>             prepareIncrementalUpgradeScriptStep.<span>Execute</span><span>();
</span><span>504</span>             IEnumerable<span>ActionGroup<span>></span> incrementalUpgradeActionGroups <span>=</span><span> prepareIncrementalUpgradeScriptStep.GetIncrementalUpgradeActionGroups();
</span><span>505</span>             foreach (ActionGroup <span>current</span> <span>in</span><span> incrementalUpgradeActionGroups)
</span><span>506</span> <span>            {
</span><span>507</span>                 ActionGroupScripter actionGroupScripter <span>=</span> <span>current</span><span>.GetActionGroupScripter(ScriptTarget.Sql100);
</span><span>508</span> <span>                this.OnActionUpdate(actionGroupScripter.Description);
</span><span>509</span> <span>            }
</span><span>510</span> <span>            this.OnScriptUpdate(prepareIncrementalUpgradeScriptStep.CompleteScript);
</span><span>511</span>             this.OnModelUpdate(this.GetChangeResultOutput(dacType.Definition.Databases<span>[</span><span>"Dac"</span><span>]</span>, dacType2.Definition.Databases<span>[</span><span>"Dac"</span><span>]</span><span>));
</span><span>512</span> <span>        }
</span><span>513</span>         <span>public</span><span> string GetDatabaseScript(ServerConnection serverConnection, string databaseName)
</span><span>514</span> <span>        {
</span><span>515</span>             string input <span>=</span><span> string.Empty;
</span><span>516</span> <span>            try
</span><span>517</span> <span>            {
</span><span>518</span>                 IServer offlineDatabase <span>=</span><span> InternalUIHooks.GetOfflineDatabase(serverConnection, databaseName);
</span><span>519</span>                 PrepareDeploymentScriptStep prepareDeploymentScriptStep <span>=</span><span> new PrepareDeploymentScriptStep(offlineDatabase, databaseName, new TargetEngineInfo(serverConnection), true);
</span><span>520</span>                 prepareDeploymentScriptStep.<span>Execute</span><span>();
</span><span>521</span>                 input <span>=</span><span> prepareDeploymentScriptStep.CompleteDatabaseObjectsScript;
</span><span>522</span> <span>            }
</span><span>523</span> <span>            catch (Exception exception)
</span><span>524</span> <span>            {
</span><span>525</span> <span>                InternalUIHooks.ThrowExceptionMessage(exception);
</span><span>526</span> <span>            }
</span><span>527</span>             Regex regex <span>=</span> new Regex("<span>^</span><span>RAISERROR</span>.<span>*</span>\\nGO.<span>*</span><span>\\n", RegexOptions.Multiline);
</span><span>528</span>             <span>return</span> regex.<span>Replace</span><span>(input, Environment.NewLine);
</span><span>529</span> <span>        }
</span><span>530</span>         <span>public</span><span> void Apply(ServerConnection serverConnection, string sql, string databaseName)
</span><span>531</span> <span>        {
</span><span>532</span>             <span>Database</span> <span>database</span> <span>=</span> new Server(serverConnection).Databases<span>[</span><span>databaseName</span><span>]</span><span>;
</span><span>533</span> <span>            try
</span><span>534</span> <span>            {
</span><span>535</span>                 string <span>text</span> <span>=</span><span> "Dac";
</span><span>536</span>                 DacStore dacStore <span>=</span><span> new DacStore(serverConnection);
</span><span>537</span>                 DacDefinition dacDefinition <span>=</span> new DacDefinition(dacStore, <span>text</span><span>, databaseName);
</span><span>538</span>                 <span>if</span><span> (!dacDefinition.IsRegistered)
</span><span>539</span> <span>                {
</span><span>540</span>                     <span>text</span> <span>=</span><span> "Dac";
</span><span>541</span> <span>                    dacDefinition.Register();
</span><span>542</span> <span>                }
</span><span>543</span>                 <span>else</span>
<span>544</span> <span>                {
</span><span>545</span>                     <span>text</span> <span>=</span> dacStore.DacInstances<span>[</span><span>databaseName</span><span>]</span><span>.Type.Name;
</span><span>546</span> <span>                }
</span><span>547</span>                 DacCompilationUnit dacCompilationUnit <span>=</span> new DacCompilationUnit(<span>text</span>, new Version(<span>1</span>, <span>0</span>), <span>database</span><span>.Collation);
</span><span>548</span> <span>                dacCompilationUnit.AddTSqlSourceFile("input.sql", sql);
</span><span>549</span>                 DacCompilationResult dacCompilationResult <span>=</span><span> dacCompilationUnit.Compile();
</span><span>550</span>                 <span>if</span> (dacCompilationResult.Errors.<span>Count</span><span>DacCompilationError<span>></span>() <span>></span> <span>0</span><span>)
</span><span>551</span> <span>                {
</span><span>552</span>                     StringBuilder stringBuilder <span>=</span><span> new StringBuilder();
</span><span>553</span>                     foreach (DacCompilationError <span>current</span> <span>in</span><span> dacCompilationResult.Errors)
</span><span>554</span> <span>                    {
</span><span>555</span>                         stringBuilder.Append(<span>current</span><span>.Message);
</span><span>556</span> <span>                    }
</span><span>557</span> <span>                    throw new Exception(stringBuilder.ToString());
</span><span>558</span> <span>                }
</span><span>559</span>                 DacType dacType <span>=</span><span> dacCompilationResult.DacType;
</span><span>560</span>                 IServer offlineDatabase <span>=</span><span> InternalUIHooks.GetOfflineDatabase(serverConnection, databaseName);
</span><span>561</span>                 this.OnModelUpdate(this.GetChangeResultOutput(offlineDatabase.Databases<span>[</span><span>databaseName</span><span>]</span>, dacType.Definition.Databases<span>[</span><span>text</span><span>]</span><span>));
</span><span>562</span> <span>                this.OnScriptUpdate(dacStore.GetIncrementalUpgradeScript(databaseName, dacType));
</span><span>563</span> <span>                dacStore.IncrementalUpgrade(databaseName, dacType, new DacUpgradeOptions());
</span><span>564</span> <span>            }
</span><span>565</span> <span>            catch (Exception exception)
</span><span>566</span> <span>            {
</span><span>567</span> <span>                InternalUIHooks.ThrowExceptionMessage(exception);
</span><span>568</span> <span>            }
</span><span>569</span> <span>        }
</span><span>570</span> <span>        private string GetChangeResultOutput(IDatabase sourceDatabase, IDatabase targetDatabase)
</span><span>571</span> <span>        {
</span><span>572</span>             ChangeResult changeResult <span>=</span><span> Differencer.Compare(sourceDatabase, targetDatabase, this.GetDefaultDifferencerFilter());
</span><span>573</span>             StringBuilder stringBuilder <span>=</span><span> new StringBuilder();
</span><span>574</span>             using (XmlWriter xmlWriter <span>=</span> XmlWriter.<span>Create</span><span>(stringBuilder, new XmlWriterSettings
</span><span>575</span> <span>            {
</span><span>576</span>                 Indent <span>=</span><span> true, 
</span><span>577</span>                 IndentChars <span>=</span><span> "   ", 
</span><span>578</span>                 NewLineChars <span>=</span><span> Environment.NewLine, 
</span><span>579</span>                 CloseOutput <span>=</span><span> false
</span><span>580</span> <span>            }))
</span><span>581</span> <span>            {
</span><span>582</span> <span>                InternalUIHooks.DifferencerTestUtils.WriteChangeResult(xmlWriter, changeResult);
</span><span>583</span> <span>            }
</span><span>584</span>             <span>return</span><span> stringBuilder.ToString();
</span><span>585</span> <span>        }
</span><span>586</span> <span>        private static void ThrowExceptionMessage(Exception exception)
</span><span>587</span> <span>        {
</span><span>588</span>             StringBuilder stringBuilder <span>=</span><span> new StringBuilder();
</span><span>589</span>             <span>while</span> (exception <span>!=</span> <span>null</span><span>)
</span><span>590</span> <span>            {
</span><span>591</span>                 stringBuilder.AppendLine("<span>-></span>" <span>+</span><span> exception.Message);
</span><span>592</span>                 exception <span>=</span><span> exception.InnerException;
</span><span>593</span> <span>            }
</span><span>594</span> <span>            throw new Exception(string</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>
Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Article précédent:oracle10.2.0.1下载链接Article suivant:Oracle LogMiner 使用