示例#1
0
        /// <summary>
        /// Drops a linked server connection.
        /// </summary>
        /// <param name="serverInstance">The local server instance.</param>
        /// <param name="remoteInstance">The remote server instance.</param>
        public void DropLinkedServer(Jhu.Graywulf.Registry.ServerInstance remoteInstance)
        {
            Server s = this.GetSmoServer();

            s.LinkedServers[remoteInstance.GetCompositeName()].Drop();

            this.Context.LogEvent(new Event("Jhu.Graywulf.Registry.ServerInstance.DropLinkedServer", this.Guid));
        }
示例#2
0
        /// <summary>
        /// Creates a linked server to a remote SQL Server instance with customizable credentials.
        /// </summary>
        /// <param name="serverInstance">The local SQL Server instance.</param>
        /// <param name="remoteInstance">The remote SQL Server instance.</param>
        /// <param name="name">Name of the linked server.</param>
        /// <param name="userName">Username to use for authenticating the connection.</param>
        /// <param name="password">Password to use for authenticating the connection.</param>
        public void CreateLinkedServer(Jhu.Graywulf.Registry.ServerInstance remoteInstance, string name, string userName, string password)
        {
            if (this.Guid == remoteInstance.Guid)
            {
                throw new DeployException(ExceptionMessages.LinkedServerCannotPointToItself);
            }

            Server s = this.GetSmoServer();

            LinkedServer ls = new LinkedServer(s, name);

            // TODO
            ls.Catalog              = string.Empty;
            ls.CollationCompatible  = false;        // ???
            ls.CollationName        = string.Empty;
            ls.ConnectTimeout       = 0;            // ???
            ls.DataAccess           = true;
            ls.DataSource           = string.Empty;
            ls.DistPublisher        = false;
            ls.Distributor          = false;
            ls.LazySchemaValidation = true;
            //ls.LinkedServerLogins
            ls.Location           = string.Empty; //?
            ls.ProductName        = "SQL Server";
            ls.ProviderName       = string.Empty; // OLE DB only
            ls.ProviderString     = string.Empty; // OLE DB only
            ls.Publisher          = false;
            ls.QueryTimeout       = 0;            // ???
            ls.Rpc                = true;
            ls.RpcOut             = true;
            ls.Subscriber         = false;
            ls.UseRemoteCollation = true;

            s.LinkedServers.Add(ls);

            ls.Create();

            if (userName != null && password != null)
            {
                // Drop default login (impersonate)
                ls.LinkedServerLogins[0].Drop();

                // Create login for sql authentication
                LinkedServerLogin login = new LinkedServerLogin(ls, string.Empty);
                login.Impersonate = false;
                login.RemoteUser  = userName;
                login.SetRemotePassword(password);

                ls.LinkedServerLogins.Add(login);

                login.Create();
            }

            this.Context.LogEvent(new Event("Jhu.Graywulf.Registry.ServerInstance.CreateLinkedServer", this.Guid));
        }
示例#3
0
        /// <summary>
        /// Checks if the liked server connection between the local and a remote server exists.
        /// </summary>
        /// <param name="serverInstance">The local SQL Server instance.</param>
        /// <param name="remoteInstance">The remote SQL Server instance.</param>
        /// <returns></returns>
        public bool CheckLinkedServerExist(Jhu.Graywulf.Registry.ServerInstance remoteInstance)
        {
            if (this.Guid == remoteInstance.Guid)
            {
                throw new DeployException(ExceptionMessages.LinkedServerCannotPointToItself);
            }

            Server s = this.GetSmoServer();

            return(s.LinkedServers.Contains(remoteInstance.GetCompositeName()));
        }
示例#4
0
 public ServerInstance(Jhu.Graywulf.Registry.ServerInstance e)
     : base(e)
 {
     InitializeMembers();
 }
示例#5
0
 /// <summary>
 /// Creates a linked server to a remote SQL Server instance.
 /// </summary>
 /// <param name="serverInstance">The local SQL Server instance.</param>
 /// <param name="remoteInstance">The remote SQL Server instance.</param>
 public void CreateLinkedServer(Jhu.Graywulf.Registry.ServerInstance remoteInstance)
 {
     CreateLinkedServer(remoteInstance, remoteInstance.GetCompositeName(), null, null);
 }