About this article: This article is reviewed against the cited sources. This is source research, not lab validation. Check the stated versions and your own requirements before making changes.
After a Windows computer is renamed, SQL Server recognises the new name at startup, but @@SERVERNAME and the sys.servers entry for the local server keep the name from installation. Microsoft's fix is to remove the old local name with sp_dropserver, add the new one with sp_addserver ..., local, and restart the instance. A VM cloned from a template and given a new computer name is in the same position, and the restart is an outage, so plan it.
What the error means
SQL Server Setup sets the server name to the computer name during installation. Microsoft documents that when the computer is renamed, "the new name is recognized during SQL Server startup", so you do not need to run Setup again, but the system metadata in sys.servers and the value returned by @@SERVERNAME are not updated automatically.
Two different functions can disagree after a rename. Microsoft states that the ServerName property of SERVERPROPERTY "automatically reports changes in the network name of the computer", while @@SERVERNAME "doesn't report such changes" and reports only changes made with sp_addserver or sp_dropserver. Comparing @@SERVERNAME with SERVERPROPERTY('ServerName') tells you whether the name is stale. Microsoft describes the ServerName property as "Both the Windows server and instance information", so it carries the instance name on a named instance, as @@SERVERNAME does. SERVERPROPERTY('MachineName') is only the Windows computer name, so on a named instance it never equals @@SERVERNAME; do not use it for this comparison.
What @@SERVERNAME returns also depends on the kind of instance. Microsoft's table, which holds "if the local server name didn't change since it was set up", gives <servername> for a default instance and <servername>\<instancename> for a named instance. For a failover cluster instance it gives the network name of the instance in the cluster, with the instance name added for a named one. After a rename, the computer part of that value is whatever was last set, which is why a restarted instance can still answer to its old name in this one function.
The new name still works for connections after the restart, because SQL Server picks up the computer name at startup. That is why the fault is easy to miss: clients connect, and the stale value only shows up in code that calls @@SERVERNAME, in the sys.servers entry for the local server, or in tools that read either.
Version scope: Microsoft's rename page is marked "SQL Server on Windows" and gives no earlier version limit; it covers stand-alone instances, default and named. A failover cluster instance has its own rename procedure, and the page points to it. The page does not describe cloning, so treat a clone that boots with a new computer name as a rename.
Likely causes
| Cause | What you see | How to confirm |
|---|---|---|
| The computer was renamed and the local server name was never updated | @@SERVERNAME returns the old name; SERVERPROPERTY('ServerName') returns the new one |
Run the comparison query in the next section |
| A VM was cloned from a template and given a new computer name | @@SERVERNAME returns the template's name |
Same query; the old name is the template's computer name, and MachineName shows the new one |
sp_addserver was run but the instance has not restarted |
The new name is set, but the change is not live | Microsoft: the local definition "takes effect only after the Database Engine is restarted" |
| Only the letter case differs | The two values match apart from upper and lower case | Compare ignoring case; see the SERVERPROPERTY note below |
| A named instance was handled like a default instance | The computer part changed but the instance part is missing or wrong | @@SERVERNAME and SERVERPROPERTY('ServerName') should both read <computername>\<instancename> |
Prove the cause before changing anything
All of these only read.
SELECT @@SERVERNAME AS at_at_servername,
SERVERPROPERTY('MachineName') AS machine_name,
SERVERPROPERTY('ServerName') AS serverproperty_servername;
SELECT server_id, name, is_linked
FROM sys.servers
ORDER BY server_id;
For sys.servers, Microsoft documents that the row with server_id = 0 is the local server, and that its name column holds the server name. Rows with server_id above 0 are linked or remote servers.
How to read the result:
@@SERVERNAMEdiffers fromSERVERPROPERTY('ServerName')by more than case: the local name is stale. Use the fix below.MachineNameshows the current computer name, which is the value the new local name must start with.@@SERVERNAMEandServerNamematch: nothing is stale. On a default instance all three values match; on a named instanceMachineNameis only the computer part. Look elsewhere, for example at a connection string that still uses the old name.- The values differ only in case: this can be a false alarm. Microsoft documents that
SERVERPROPERTY('ServerName')changed between SQL Server 2019 builds. RTM returned uppercase, CU 1 to CU 8 returned the name as saved, CU 9 to CU 12 returned uppercase, and CU 13 onwards return the name as saved. If the Windows name has lowercase letters, that can differ from@@SERVERNAMEwithout any rename.
Before you change anything, find what depends on the old name. Microsoft lists the following effects:
- Linked server definitions that refer to the computer name need updating with
sp_addlinkedserverorsp_setnetname. - Client aliases that use named pipes break, because the pipe path contains the old name.
- Windows groups with a hard-coded computer name may stop granting access.
- Reporting Services may be unavailable after the rename.
- Microsoft says SQL Server does not support renaming computers that are involved in replication, except when log shipping is used with replication, and that database mirroring must be turned off before the rename.
Also run SELECT name, is_published, is_merge_published, is_distributor FROM sys.databases;. Microsoft documents is_published (transactional or snapshot publication), is_merge_published (merge publication) and is_distributor (distribution database). The same page says is_subscribed "isn't used" and "will always return 0", so this query cannot show a subscriber. Ask whoever runs replication whether this computer subscribes to anything before you treat the replication restriction as not applying.
Fix
Run this during a quiet window. Microsoft's procedure for a default instance is:
EXECUTE sp_dropserver '<old_name>';
GO
EXECUTE sp_addserver '<new_name>', local;
GO
Use the exact @@SERVERNAME value for <old_name>: Microsoft states that @server "must exist". Then restart the instance. For a named instance use '<old_name\instancename>' and '<new_name\instancename>'. The instance name part cannot change with these steps.
Disruptive step: sp_dropserver removes the old local server entry and sp_addserver defines the new one. Microsoft warns that using them to change the local server name "can cause unintended effects or unsupported configurations", and that sp_addserver may cause undesired effects when availability groups or replication are in use. Neither procedure can run inside a user-defined transaction. They need ALTER ANY LINKED SERVER and the setupadmin role respectively. To back out, run sp_dropserver on the new name, sp_addserver on the old name with local, and restart again. Only one local server can be defined for an instance.
Disruptive step: the restart drops every connection while the instance is down, and there is no way to defer the new name without it. Use your normal change window.
Remote logins. If sp_dropserver fails with Msg 15190, Microsoft shows the text There are still remote logins for the server 'SERVER1'. Drop the remote logins for that name first, with EXECUTE sp_dropremotelogin old_name;, or pass the droplogins argument to sp_dropserver.
Disruptive step: dropping remote or linked server logins removes those mappings, and you have to recreate them. Note each mapping before you start.
Linked servers. Update any entry that points at the old computer name with sp_addlinkedserver or sp_setnetname, as Microsoft directs. The linked server pages describe the arguments.
Risk: changing a linked server's name or network name changes where queries and jobs that use it connect. Note the current definition first (sys.servers shows it) and restore the old values to back out.
Order of work. Microsoft's page expects the two procedures first and the restart after them. Write down the old name and every setting named above before you begin, tell the application owners about the restart, and run the statements on the instance itself rather than through a linked server. If the instance is part of a failover cluster, a mirroring pair, an availability group or a replication topology, stop and use the supporting Microsoft pages for that feature instead of this procedure.
Confirm the fix
After the restart, run the comparison query again. @@SERVERNAME and SERVERPROPERTY('ServerName') should match (ignoring case, as described above), and the server_id = 0 row in sys.servers should show the new name. Then connect from a client using the new name, test each linked server with EXECUTE sp_testlinkedserver N'<linked server name>'; (Microsoft documents that it raises an exception with the reason if the test fails), and run one SQL Agent job.
Example (illustrative): a template VM sqltpl01 runs a default SQL Server instance. It is cloned and renamed sql02. The comparison query on sql02 returns SQLTPL01 for @@SERVERNAME and SQL02 for both ServerName and MachineName. No database is published or merge published, none is a distributor, and the replication owner confirms sql02 subscribes to nothing. The administrator runs sp_dropserver 'SQLTPL01' and sp_addserver 'SQL02', local, restarts the instance in the 22:00 window, and the query then returns SQL02 in both columns. One linked server pointing at sqltpl01 is updated separately.
What to watch afterwards
- Add a check to the template build that compares
@@SERVERNAMEwithSERVERPROPERTY('ServerName')on first boot of each clone. - Search SQL Agent jobs, scripts and reports for the old name as text.
- Keep the old name in DNS as an alias only while clients are moved over.
- After any rename, test Windows-group logins and client aliases that name the computer.
Read next
Related articles you may want next.
- VMwareHow to build and validate Windows Server templates for VMwareCreate a repeatable image with deliberate identity preparation and two-clone acceptance testing.Read article
- VMwareWindows guest customization fails: read the Sysprep and customization logsWindows guest customization failed? Read VMware's customization logs, then the Sysprep logs in Panther, to find the step that broke before changing it.Read article
- TroubleshootingSQL Agent Reports Success but the Import Failed: Audit Job-Step OutcomesTrace job-step control flow and exit semantics to make the final result reflect the required business output.Read article
Risks and limits
These commands have not been run or lab-tested. Microsoft's pages do not tie a stale server name to any one error number beyond the remote login message above, and they do not describe cloning, so the clone case is a reasoned application of the rename procedure. Do not run these steps on a computer involved in replication, mirroring or an availability group without the supporting pages. For a failover cluster instance use Microsoft's separate rename procedure.
Sources
- Rename a computer that hosts a stand-alone instance of SQL Server — Microsoft Learn, page dated 2026-07-20, accessed 18 November 2026
- sp_dropserver (Transact-SQL) — Microsoft Learn, page dated 2026-08-24, accessed 18 November 2026
- sp_addserver (Transact-SQL) — Microsoft Learn, page dated 2026-06-22, accessed 18 November 2026
- @@SERVERNAME (Transact-SQL) — Microsoft Learn, page dated 2026-02-10, accessed 18 November 2026
- SERVERPROPERTY (Transact-SQL) — Microsoft Learn, page dated 2026-09-21, accessed 18 November 2026
- sys.servers (Transact-SQL) — Microsoft Learn, page dated 2026-07-20, accessed 18 November 2026
- sp_testlinkedserver (Transact-SQL) — Microsoft Learn, page dated 2026-08-24, accessed 18 November 2026
- sys.databases (Transact-SQL) — Microsoft Learn, page dated 2026-09-21, accessed 18 November 2026
This article was originally published on .