SQL

Migrate SQL Server to a New Domain in 5 Steps

8 min read

SQL Server logins that use Windows accounts break when the instance moves to a new Active Directory domain. The old account names point to a domain that no longer applies and every user sees a login failure.

Five steps below move the instance, the logins, the database users, the service account and the SPN to the new domain. Every step names its risk.

Quick SummaryMigrate SQL Server to a new domain in five steps. Move the databases with a backup first. Create a new login for every account of the new domain. Fix the orphaned users with ALTER USER. Replace the service account in SQL Server Configuration Manager. Register the SPN for the new account. Test the connections before users return.

Why Do Windows Logins Fail After a Domain Move?

A Windows login stores the security identifier (SID) of the domain account. A new domain gives the same person a new account with a new SID. The stored login matches nobody.

Microsoft states that ALTER LOGIN with the WITH NAME option works for a Windows login only when the SID of the new name matches the SID of the existing login. An account of another domain has another SID. Renaming the login does not work and you create a new login instead.

Object What breaks Step that fixes it
Windows login The SID belongs to the old domain Method 2
Database user The user carries the SID of the old login and becomes an orphaned user Method 3
Service account The account of the old domain cannot start the service Method 4
Kerberos connection The SPN points to the old account Method 5
SQL login Nothing breaks. SQL logins have no domain No fix needed

Do You Know?A SQL login has no domain. It works after the move. Retain one SQL login with the sysadmin role until all tests pass.

Which Move Fits Your Case?

Your situation Approach Data risk
The same server joins the new domain Methods 2 to 5 on the same instance None
A new server in the new domain takes over Method 1 and then Methods 2 to 5 None when you test the restore
Only a few users move to the new domain Method 2 for those users None
Database files are damaged before the move Recover the files first with SQL Recovery None on the original files

How Do You Migrate SQL Server to a New Domain?

Method 1: Move the Databases With Backup and Restore

Ignore this step when the same server joins the new domain. A new server needs the databases first.

BACKUP DATABASE SalesDB
TO DISK = N'D:\Backup\SalesDB.bak'
WITH CHECKSUM, INIT;

RESTORE VERIFYONLY
FROM DISK = N'D:\Backup\SalesDB.bak'
WITH CHECKSUM;

Copy the file to the new server and restore it. The post on moving a database to a new server lists the restore options and the post on moving an entire instance explains the system databases.

Method 2: Create New Logins for the New Domain

Create one login for every account of the new domain. Use the domain name of the new domain in front of the account.

CREATE LOGIN [NEWDOMAIN\priya] FROM WINDOWS;
CREATE LOGIN [NEWDOMAIN\SalesTeam] FROM WINDOWS;

ALTER SERVER ROLE sysadmin ADD MEMBER [NEWDOMAIN\priya];

Grant the same server roles that the old login had. Prefer a group over a single account because a group login serves every member.

Heads UpA broken Windows login can shut every administrator out of the instance. Create the new administrator login before you remove the old one.

Method 3: Fix the Orphaned Database Users

Find the users that have no matching login. Microsoft detects them by comparing the SID of the user with the SID of the login.

SELECT dp.name AS user_name, dp.sid
FROM sys.database_principals AS dp
LEFT JOIN sys.server_principals AS sp
  ON dp.sid = sp.sid
WHERE sp.sid IS NULL
  AND dp.authentication_type_desc = N'WINDOWS'
  AND dp.name NOT IN (N'dbo', N'guest', N'INFORMATION_SCHEMA', N'sys');

Map every orphaned user to the new login. A recreated login gets a different SID. The mapping is the fix.

USE SalesDB;
ALTER USER [OLDDOMAIN\priya] WITH LOGIN = [NEWDOMAIN\priya];

Microsoft marks sp_change_users_login as deprecated and states that it cannot map Windows principals. Use ALTER USER. The post on error 15023 explains the failure when a user already exists.

Method 4: Replace the Service Account

Replace the service account in SQL Server Configuration Manager. Microsoft states that the tool encrypts again the service master key and sets the permissions that the service needs. The Services console does neither.

Select SQL Server Services, open the properties of SQL Server and enter the account of the new domain on the Log On tab. The Database Engine restarts after the update.

Account type Use when
Domain user account The instance needs network access, for example linked servers or Kerberos
Group managed service account The domain has Windows Server 2012 or later and you want automatic password management
Local account The instance stays on one server with no network access

Method 5: Register the SPN for the New Account

Kerberos needs a service principal name (SPN) that points to the service account. Microsoft states that the SPN must map to the account that starts the service or the connection falls back to NTLM.

setspn -L NEWDOMAIN\sqlsvc

setspn -S MSSQLSvc/sqlserver01.newdomain.com:1433 NEWDOMAIN\sqlsvc

SELECT session_id, auth_scheme
FROM sys.dm_exec_connections
WHERE session_id = @@SPID;

An auth_scheme of KERBEROS means that the SPN works. NTLM means that it does not. Delete the old SPN with setspn -D when the old account still owns it. The delete and register order after the service account moves is my own advice and not a Microsoft statement.

Which Checks Prove That the Domain Move Worked?

Check Query or action Expected result
Logins exist Query sys.server_principals for the types WINDOWS_LOGIN and WINDOWS_GROUP Every account of the new domain
No orphaned users The query of Method 3 Zero rows
Service account Query sys.dm_server_services for the service_account column The account of the new domain
Kerberos The auth_scheme query of Method 5 KERBEROS
Agent tasks Open SQL Server Agent and check the owner of every scheduled task No owner of the old domain

Common Questions on Moving SQL Server to a New Domain

Can You Rename a Windows Login to the New Domain?

No. Microsoft states that ALTER LOGIN with WITH NAME needs the SID of the new name to match the existing SID. An account of another domain has another SID. You create a new login.

Do SQL Logins Stop Working After a Domain Move?

No. A SQL login has no domain and works as before. Only the Windows logins and the Windows groups break.

How Do You Find Orphaned Users After the Move?

Compare the SID of every database user with the SID of the server logins. A user with no matching login is orphaned. Fix the user with ALTER USER and the WITH LOGIN option.

Why Does Configuration Manager Matter for the Service Account?

Microsoft states that SQL Server Configuration Manager encrypts again the service master key and sets the right permissions. The Services console does not.

Does the Domain Move Need Downtime?

Yes. Replacing the service account restarts the Database Engine. Plan the restart outside working hours.

Who, How and WhyAndrew Jackson, Technical Content Specialist, is the author of this guide. The ALTER LOGIN limit follows the Microsoft page for ALTER LOGIN. The orphaned user query and the ALTER USER fix follow the Microsoft page on orphaned users. The service account steps follow the Microsoft page on the service account steps. The SPN steps follow the Microsoft page on SPN registration. Verify every step on your version. The code was checked for syntax against Microsoft documentation and was not executed on a live server. The delete and register order of the SPN is the author’s own advice and not a Microsoft statement. The guide exists because a domain move breaks Windows logins for every user at once.

Key Takeaways

  • A Windows login stores the SID of the old domain account. A new domain needs a new login for every account.
  • ALTER LOGIN with WITH NAME cannot rename a Windows login to an account with another SID.
  • Orphaned users appear when the SID of the user has no matching login. ALTER USER with LOGIN fixes them.
  • Replace the service account only in SQL Server Configuration Manager. The Database Engine restarts after the update.
  • Register the SPN for the new service account and check the auth_scheme for KERBEROS.
  • Retain one SQL login with the sysadmin role until all tests pass.