public virtual bool IsConnectionOpen(SmoObjectBase smoObj) { SqlSmoObject sqlObj = smoObj as SqlSmoObject; return(sqlObj != null && sqlObj.ExecutionManager != null && sqlObj.ExecutionManager.ConnectionContext != null && sqlObj.ExecutionManager.ConnectionContext.IsOpen); }
public MySmoObjectBase(MySmoObjectBase mySmoObject) { SourceSmoObject = mySmoObject.SourceSmoObject; Name = mySmoObject.Name; ParentName = mySmoObject.ParentName; this.mProductionSmoObject = mySmoObject.mProductionSmoObject; ExtraParams = new string[mySmoObject.ExtraParams.Length]; mySmoObject.ExtraParams.CopyTo(ExtraParams, 0); }
/// <summary> /// Ensures the server objects connection context is open. This is used by all child objects, and /// the only way to easily access is via the server object. This should be called during access of /// any of the object properties /// </summary> public void EnsureConnectionOpen(SmoObjectBase smoObj) { if (!smoWrapper.IsConnectionOpen(smoObj)) { // We have a closed server connection. Reopen this // Note: not currently catching connection exceptions. Expect this to bubble // up to calling methods and be logged there as this would be happening there in any case smoWrapper.OpenConnection(smoObj); } }
public virtual void OpenConnection(SmoObjectBase smoObj) { SqlSmoObject sqlObj = smoObj as SqlSmoObject; if (sqlObj != null && sqlObj.ExecutionManager != null && sqlObj.ExecutionManager.ConnectionContext != null) { sqlObj.ExecutionManager.ConnectionContext.Connect(); } }
/// <summary> /// Copies the context for use by another node /// </summary> /// <param name="parent">New Parent to set</param> /// <returns>new <see cref="SmoQueryContext"/> with all fields except <see cref="Parent"/> the same</returns> public SmoQueryContext CopyWithParent(SmoObjectBase parent) { SmoQueryContext context = new SmoQueryContext(this.Server, this.ServiceProvider, this.smoWrapper) { database = this.Database, Parent = parent, SqlServerType = this.SqlServerType, ValidFor = ValidFor }; return(context); }
protected virtual void EnsureContextInitialized() { if (context == null) { SmoObjectBase smoParent = GetParentSmoObject(); SmoQueryContext parentContext = Parent?.GetContextAs <SmoQueryContext>(); if (smoParent != null && parentContext != null) { context = parentContext.CopyWithParent(smoParent); } } }
public MySmoObjectBase(SmoObjectBase smoObject, string name, string parentName, params string[] extraParams) { SourceSmoObject = smoObject; Name = name; ParentName = parentName; ExtraParams = new string[extraParams.Length]; for (int i = 0; i < extraParams.Length; i++) { ExtraParams[i] = UpgradeScriptGenerator.TrimSymbols(extraParams[i]); } }
public void QueryContextShouldReopenClosedConnectionWhenGettingParent() { // given a server connection that will state its connection is closed Server smoServer = new Server(new ServerConnection(new SqlConnection(fakeConnectionString))); Mock <SmoWrapper> wrapper = SetupSmoWrapperForIsOpenTest(smoServer, isOpen: false); SmoQueryContext context = new SmoQueryContext(smoServer, ServiceProvider, wrapper.Object); context.Parent = smoServer; // when I access the Parent property SmoObjectBase actualParent = context.Parent; // Then I expect to have open called Assert.NotNull(actualParent); wrapper.Verify(c => c.OpenConnection(It.IsAny <Server>()), Times.Once); }
public MyIndex(SmoObjectBase smoObject, string name, string parentName) : base(smoObject, ChangeName(name), parentName) { }
public MyColumn(SmoObjectBase smoObject, string name, string parentName) : base(smoObject, name, parentName) { }
public MyForeignKey(SmoObjectBase smoObject, string name, string parentName) : base(smoObject, name, parentName) { }
private bool IncludeSysObject(SmoObjectBase o) { return(arguments.IncludeSystemObjects || (o is Table ? ((Table)o).Name == "sysdiagrams" : false) || (arguments.IncludeSystemTables && o is Table)); }
private bool OutputAtEnd(SmoObjectBase o, string s) { return(o is Table && s.Contains("\nALTER") && !s.StartsWith("INSERT")); }
public MyStoredProcedure(SmoObjectBase smoObject, string name, string parentName, string textBody) : base(smoObject, name, parentName, textBody) { }
public MyTrigger(SmoObjectBase smoObject, string name, string parentName, string textBody) : base(smoObject, name, parentName, textBody) { }