zoukankan      html  css  js  c++  java
  • Rename a Computer that Hosts a Stand-Alone Instance of SQL Server

    When you change the name of the computer that is running SQL Server, the new name is recognized during SQL Server startup. You do not have to run Setup again to reset the computer name. Instead, use the following steps to update system metadata that is stored in sys.servers and reported by the system function @@SERVERNAME. Update system metadata to reflect computer name changes for remote connections and applications that use @@SERVERNAME, or that query the server name from sys.servers.

    The following steps cannot be used to rename an instance of SQL Server. They can be used only to rename the part of the instance name that corresponds to the computer name. For example, you can change a computer named MB1 that hosts an instance of SQL Server named Instance1 to another name, such as MB2. However, the instance part of the name, Instance1, will remain unchanged. In this example, the \ComputerNameInstanceName would be changed from \MB1Instance1 to \MB2Instance1. 

    Before you begin

    Before you begin the renaming process, review the following information:

    • When an instance of SQL Server is part of a SQL Server failover cluster, the computer renaming process differs from a computer that hosts a stand-alone instance.

    • SQL Server does not support renaming computers that are involved in replication, except when you use log shipping with replication. The secondary computer in log shipping can be renamed if the primary computer is permanently lost. For more information, see Log Shipping and Replication (SQL Server).

    • When you rename a computer that is configured to use Reporting Services, Reporting Services might not be available after the computer name change. For more information, see Rename a Report Server Computer.

    • When you rename a computer that is configured to use database mirroring, you must turn off database mirroring before the renaming operation. Then, re-establish database mirroring with the new computer name. Metadata for database mirroring will not be updated automatically to reflect the new computer name. Use the following steps to update system metadata.

    • Users who connect to SQL Server through a Windows group that uses a hard-coded reference to the computer name might not be able to connect to SQL Server. This can occur after the rename if the Windows group specifies the old computer name. To ensure that such Windows groups have SQL Server connectivity following the renaming operation, update the Windows group to specify the new computer name.

    You can connect to SQL Server by using the new computer name after you have restarted SQL Server. To ensure that @@SERVERNAME returns the updated name of the local server instance, you should manually run the following procedure that applies to your scenario. The procedure you use depends on whether you are updating a computer that hosts a default or named instance of SQL Server.

    Rename a computer that hosts a stand-alone instance of SQL Server

    For a renamed computer that hosts a default instance of SQL Server, run the following procedures: (对于默认实例的修改方式)

    sp_dropserver <old_name>;  --原计算机名
    GO  
    sp_addserver <new_name>, local;  --新计算机名
    GO

    Restart the instance of SQL Server.

    For a renamed computer that hosts a named instance of SQL Server, run the following procedures:(对于命名实例的修改方式)

    sp_dropserver <old_nameinstancename>;  
    GO  
    sp_addserver <new_nameinstancename>, local;  
    GO

    Restart the instance of SQL Server.

    Verify renaming operation

    • Select information from either @@SERVERNAME or sys.servers. The @@SERVERNAME function will return the new name, and the sys.servers table will show the new name. The following example shows the use of @@SERVERNAME.

    SELECT @@SERVERNAME AS 'Server Name'; 

    Additional considerations

    Remote Logins - If the computer has any remote logins, running sp_dropserver might generate an error similar to the following:

    erver: Msg 15190, Level 16, State 1, Procedure sp_dropserver, Line 44 There are still remote logins for the server 'SERVER1'.

    To resolve the error, you must drop remote logins for this server.

    Drop remote logins

    • For a default instance, run the following procedure:

    sp_dropremotelogin old_name;  
    GO

    For a named instance, run the following procedure:

    sp_dropremotelogin old_nameinstancename;  
    GO

    Linked Server Configurations - Linked server configurations will be affected by the computer renaming operation. Use sp_addlinkedserver or sp_setnetname to update computer name references. For more information, see the sp_addlinkedserver (Transact-SQL) or sp_setnetname (Transact-SQL).

    Client Alias Names - Client aliases that use named pipes will be affected by the computer renaming operation. For example, if an alias "PROD_SRVR" was created to point to SRVR1 and uses the named pipes protocol, the pipe name will look like \SRVR1pipesqlquery. After the computer is renamed, the path of the named pipe will no longer be valid and. For more informati

    =======

    SELECT  HOST_NAME() AS 'host_name()',
    @@servername AS 'ServerNameInstanceName',
    SERVERPROPERTY('servername') AS 'ServerName',
    SERVERPROPERTY('machinename') AS 'Windows_Name',
    SERVERPROPERTY('ComputerNamePhysicalNetBIOS') AS 'NetBIOS_Name',
    SERVERPROPERTY('instanceName') AS 'InstanceName',
    SERVERPROPERTY('IsClustered') AS 'IsClustered'

    If you find any mismatch, then you need to follow below steps:
     1. Execute below to drop the current server name
        EXEC sp_DROPSERVER 'oldservername'
     2. Execute below to add a new server name. Make sure local is specified.
        EXEC sp_ADDSERVER 'newservername', 'local'
     3. Restart SQL Services.
     4. Verify the new name using:
        SELECT @@SERVERNAME
        SELECT * FROM sys.servers WHERE server_id = 0
    I must point out that you should not perform rename if you are using:
     1. SQL Server is clustered.
     2. Using replication.
     3. Reporting Service is installed.
  • 相关阅读:
    在次转发IBATIS模糊查询
    IBatisNet 模糊查询
    转js动态给table添加行(tr)
    简单的ajax(菜鸟级)
    Redis消息通知系统的实现 新风宇宙
    彻底删除SVN版本库某一文件夹或文件 新风宇宙
    代码审查:ThoughtBot官方给出的代码审查指导原则 新风宇宙
    linux下php代码加密扩展beast 新风宇宙
    利用curl的API进行开发 新风宇宙
    Linux 日志服务器搭建(rsyslog+loganalyzer) 新风宇宙
  • 原文地址:https://www.cnblogs.com/rusking/p/13027240.html
Copyright © 2011-2022 走看看