public void OpenTable2(NamedSmoObject tbl, SqlConnectionInfo connection, Server server) { String fileName = null; // step1 - get script to edit table - SelectFromTableOrView(Server server, Urn urn, int topNValue) // step2 - create a file try { var t = Type.GetType("Microsoft.SqlServer.Management.UI.VSIntegration.ObjectExplorer.OpenTableHelperClass,ObjectExplorer", true, true); var miSelectFromTable = t.GetMethod("SelectFromTableOrView", BindingFlags.Static | BindingFlags.Public); //signature is: public static string SelectFromTableOrView(Server server, Urn urn, int topNValue) String script = (String)miSelectFromTable.Invoke(null, new Object[] { server, tbl.Urn, 200 }); fileName = CreateFile(script); // invoke designer var mc = new ManagedConnection(); mc.Connection = connection; if (_editTableMethod == null) { foreach (var mi in ServiceCache.ScriptFactory.GetType().GetMethods(BindingFlags.Instance | BindingFlags.NonPublic)) { if ((mi.Name == "CreateDesigner") && (mi.GetParameters().Length == 5)) { _editTableMethod = mi; break; } } } if (_editTableMethod != null) { _editTableMethod.Invoke(ServiceCache.ScriptFactory, new Object[] { DocumentType.OpenTable, DocumentOptions.ManageConnection, new Urn(tbl.Urn.ToString() + "/Data"), mc, fileName }); } else { log.Error("Could not find CreateDesigner method"); } } catch (Exception ex) { log.Error("Failed OpenTable2", ex); } finally { if (!String.IsNullOrEmpty(fileName) && File.Exists(fileName)) { File.Delete(fileName); } } }
public static void DesignTable(Table tbl, SqlConnectionInfo connInfo) { if (tbl.State == SqlSmoState.Dropped) { log.Info("trying to design dropped table."); return; } var mc = new ManagedConnection(); mc.Connection = connInfo; ServiceCache.ScriptFactory.DesignTableOrView(Microsoft.SqlServer.Management.UI.VSIntegration.Editors.DocumentType.Table, DocumentOptions.ManageConnection, tbl.Urn.ToString(), mc); }