本文整理汇总了C#中Server.GetSmoObject方法的典型用法代码示例。如果您正苦于以下问题:C# Server.GetSmoObject方法的具体用法?C# Server.GetSmoObject怎么用?C# Server.GetSmoObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Server
的用法示例。
在下文中一共展示了Server.GetSmoObject方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddItemInCollection
private static void AddItemInCollection(System.Windows.Forms.TreeViewEventArgs node, Server sqlServer)
{
Urn urnNode = (Urn)node.Node.Tag;
SqlSmoObject smoObj = sqlServer.GetSmoObject(urnNode.Parent);
TreeNode tn;
NamedSmoObject namedObj;
PropertyInfo p = smoObj.GetType().GetProperty(node.Node.Text);
if (p != null)
{
ICollection iColl = p.GetValue(smoObj, null) as ICollection;
if (iColl != null)
{
IEnumerator enum1 = iColl.GetEnumerator();
while (enum1.MoveNext())
{
tn = new TreeNode();
namedObj = enum1.Current as NamedSmoObject;
if (namedObj != null)
{
tn.Text = namedObj.Name;
}
else
{
tn.Text = ((SqlSmoObject)enum1.Current).Urn;
}
tn.Tag = ((SqlSmoObject)enum1.Current).Urn;
node.Node.Nodes.Add(tn);
AddDummyNode(tn);
}
}
else
{
Console.WriteLine(string.Format(
System.Globalization.CultureInfo.InvariantCulture,
Properties.Resources.PropertyNotICollection, p.Name));
}
}
else
{
Console.WriteLine(string.Format(
System.Globalization.CultureInfo.InvariantCulture,
Properties.Resources.PropertyNotFound, node.Node.Text));
}
}
示例2: GetScriptToMakeIdenticalObject2
private StringCollection GetScriptToMakeIdenticalObject2()
{
StringCollection collScript = new StringCollection();
Server server1 = new Server(this.serverConn2);
Server server2 = new Server(this.serverConn1);
SqlSmoObject object1 = server1.GetSmoObject(this.urnTextBox2.Text);
SqlSmoObject object2 = server2.GetSmoObject(this.urnTextBox1.Text);
Database database1 = object1 as Database;
Database database2 = object2 as Database;
server1.ConnectionContext.SqlExecutionModes = SqlExecutionModes.CaptureSql;
object1.Refresh();
object2.Refresh();
foreach (Property p in object2.Properties)
{
try
{
if (p.Writable && object2.Properties[p.Name].Value != null &&
!object1.Properties[p.Name].Value.Equals(object2.Properties[p.Name].Value))
object1.Properties[p.Name].Value = object2.Properties[p.Name].Value;
}
catch (PropertyCannotBeRetrievedException)
{
// Ignore properties that can't be accessed
}
}
if (database1 != null && database2 != null)
{
foreach (Property p in database1.DatabaseOptions.Properties)
{
// If the props differ in value update the destination database
if (!p.IsNull
&& !database1.DatabaseOptions.Properties[p.Name].IsNull
&& database1.DatabaseOptions.Properties[p.Name].Writable)
{
if (!database1.DatabaseOptions.Properties[p.Name].Value
.Equals(database2.DatabaseOptions.Properties[p.Name].Value))
{
database1.DatabaseOptions.Properties[p.Name].Value =
database2.DatabaseOptions.Properties[p.Name].Value;
}
}
}
}
server1.ConnectionContext.CapturedSql.Clear();
server2.ConnectionContext.CapturedSql.Clear();
IAlterable alterableObject1 = object1 as IAlterable;
if (alterableObject1 != null)
{
try
{
alterableObject1.Alter();
collScript = server1.ConnectionContext.CapturedSql.Text;
}
catch (SmoException ex)
{
ExceptionMessageBox emb = new ExceptionMessageBox(ex);
emb.Show(this);
}
}
server1.ConnectionContext.SqlExecutionModes = SqlExecutionModes.ExecuteSql;
if (collScript.Count == 0)
{
collScript.Add(Properties.Resources.SelectedObjectsIdentical);
}
return collScript;
}
示例3: Setup
private void Setup(Urn urn1, Urn urn2)
{
if (serverName1 == null || serverName2 == null)
{
throw new ApplicationException(
Properties.Resources.ServerPropertiesCannotBeNull);
}
server1 = new Server(serverName1);
server2 = new Server(serverName2);
if (loginName1 == null || loginName1.Length == 0)
{
server1.ConnectionContext.LoginSecure = true;
}
else
{
server1.ConnectionContext.LoginSecure = false;
server1.ConnectionContext.Login = loginName1;
server1.ConnectionContext.Password = password1;
}
if (loginName2 == null || loginName2.Length == 0)
{
server2.ConnectionContext.LoginSecure = true;
}
else
{
server2.ConnectionContext.LoginSecure = false;
server2.ConnectionContext.Login = loginName2;
server2.ConnectionContext.Password = password2;
}
try
{
smoObject1 = server1.GetSmoObject(urn1);
}
catch (ApplicationException ex)
{
WriteLine(string.Format(System.Globalization.CultureInfo.InvariantCulture,
Properties.Resources.ErrorCreatingFirstObject, ex));
throw new ApplicationException(
Properties.Resources.ErrorCreatingFirstObjectException,
ex);
}
try
{
smoObject2 = server2.GetSmoObject(urn2);
}
catch (ApplicationException ex)
{
WriteLine(string.Format(System.Globalization.CultureInfo.InvariantCulture,
Properties.Resources.ErrorCreatingSecondObject, ex));
throw new ApplicationException(
Properties.Resources.ErrorCreatingSecondObjectException,
ex);
}
if (smoObject1 == null)
{
throw new ApplicationException(string.Format(
System.Globalization.CultureInfo.InvariantCulture,
Properties.Resources.ObjectNotCreated, urn1));
}
if (smoObject2 == null)
{
throw new ApplicationException(string.Format(
System.Globalization.CultureInfo.InvariantCulture,
Properties.Resources.ObjectNotCreated, urn2));
}
}
示例4: shallowCompareButton_Click
/// <summary>
/// Handle the shallow comparison
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void shallowCompareButton_Click(object sender, EventArgs e)
{
Cursor csr = this.Cursor;
this.Cursor = Cursors.WaitCursor;
string[] items;
ListViewItem listViewItem;
try
{
if (ValidateFields())
{
try
{
object val1 = null, val2 = null;
CleanTheForm();
shallowCompareButton.Refresh();
shallowCompareButton.Enabled = false;
this.paramUrn1 = (Urn)this.urnTextBox1.Text;
this.paramUrn2 = (Urn)this.urnTextBox2.Text;
Server server1 = new Server(this.serverConn1);
Server server2 = new Server(this.serverConn2);
SqlSmoObject object1 = server1.GetSmoObject(urnTextBox1.Text);
SqlSmoObject object2 = server2.GetSmoObject(urnTextBox2.Text);
object1.Refresh();
object2.Refresh();
foreach (Property prop in object2.Properties)
{
try
{
val1 = object1.Properties[prop.Name].Value;
val2 = object2.Properties[prop.Name].Value;
if (val1 != null && val2 != null)
{
if (!val1.Equals(val2))
{
items = new string[5];
items[0] = prop.Name;
items[1] = object1.Urn;
items[2] = object2.Urn;
if (val1 != null)
{
items[3] = val1.ToString();
}
else
{
items[3] = "null";
}
if (val2 != null)
{
items[4] = val2.ToString();
}
else
{
items[4] = "null";
}
listViewItem = new ListViewItem(items);
differencesListView.Items.Add(listViewItem);
differencesListView.Refresh();
}
}
}
catch (PropertyCannotBeRetrievedException)
{
// Ignore properties that can't be accessed
}
}
Database database1 = object1 as Database;
Database database2 = object2 as Database;
if (database1 != null && database2 != null)
{
foreach (Property p in database1.DatabaseOptions.Properties)
{
// If the props differ in value update the destination database
if (!p.IsNull
&& !database1.DatabaseOptions.Properties[p.Name].IsNull
&& database1.DatabaseOptions.Properties[p.Name].Writable)
{
if (!database1.DatabaseOptions.Properties[p.Name].Value.Equals
(database2.DatabaseOptions.Properties[p.Name].Value))
{
items = new string[5];
items[0] = p.Name;
items[1] = object1.Urn + "/Options";
items[2] = object2.Urn + "/Options";
//.........这里部分代码省略.........