When renaming a computer hosting SQL Server, you need to update system metadata to maintain connectivity for remote connections and applications.
This process involves updating SQL Server’s registered hostname to match the new computer name.
Quick Steps to Update SQL Server After a Hostname Change:
1. Rename the Computer & Reboot:
Update the Windows computer name.
![sql server connect to server](https://peter-whyte.com/wp-content/uploads/2018/04/1.-Connection-Window.png)
![Cannot connect to server SQL](https://peter-whyte.com/wp-content/uploads/2018/04/2.-Connection-Error.png)
2. Connect to SQL Server:
Use localhost
temporarily if a connection error occurs.
3. Check Hostnames:
Run xp_getnetname
to verify the current hostname.
![@@SERVERNAME SQL Server](https://peter-whyte.com/wp-content/uploads/2018/04/3.-Get-Server-name-info.png)
4. Update SQL Metadata:
Drop the old name with sp_dropserver
and register the new one using sp_addserver
.
![sp_dropserver example](https://peter-whyte.com/wp-content/uploads/2018/04/4.-Drop-currently-registered-name.png)
![sp_addserver example](https://peter-whyte.com/wp-content/uploads/2018/04/4.-Register-new-hostname.png)
5. Restart SQL Server:
Apply changes by restarting the service.
![restart-service *MSSQL* PowerShell](https://peter-whyte.com/wp-content/uploads/2018/04/5.-Restart-SQL-Server.png)
6. Verify Changes:
Confirm the update by checking the new hostname.
![Renamed SQL Server](https://peter-whyte.com/wp-content/uploads/2018/04/6.-Get-Server-name-info.png)
When you next open SSMS, ‘localhost’ should be shown in the Server name field. Changing this to your new hostname will now work.
Detailed Guide Available:
For a complete, step-by-step walkthrough with code and MS Docs links, check out my other post: How to Rename a Computer that Hosts SQL Server
SQL Code Used
-- Get currently registered hostname: SELECT @@SERVERNAME AS 'Old Server Name' -- Get EXEC xp_getnetname -- Drop current hostname registration. USE [master] GO sp_dropserver 'enter old hostname returned by @@SERVERNAME above' GO --Register new hostname. USE [master] GO sp_addserver 'enter hostname returned from xp_getnetname above',local -- having local updates the metadata for @@SERVERNAME GO -- Restart SQL to apply changes
Leave a Reply