You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: support/sql/database-engine/security/transfer-logins-passwords-between-instances.md
+14-13Lines changed: 14 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,39 +1,40 @@
1
1
---
2
-
title: Transfer logins and passwords between instances
3
-
description: This article describes how to transfer the logins and the passwords between different instances of SQL Server running on Windows.
2
+
title: Transfer SQL Server Logins and Passwords Between Instances
3
+
description: Learn how to transfer logins and passwords between SQL Server instances to maintain user access and security during migrations or restores.
# Transfer logins and passwords between instances of SQL Server
12
11
13
-
This article describes how to transfer the logins and passwords between different instances of Microsoft SQL Server running on Windows. The instances might be on the same server or different servers, and their versions might differ.
14
-
15
12
_Original product version:_ SQL Server
16
13
_Original KB number:_ 918992, 246133
17
14
15
+
## Summary
16
+
17
+
This article describes how to transfer the logins and passwords between different instances of Microsoft SQL Server running on Windows. Use these procedures when you migrate databases between servers or need to maintain consistent user access across SQL Server instances. The instances might be on the same server or different servers, and their versions might differ.
18
+
18
19
## Why transfer logins between SQL Server instances?
19
20
20
-
In this article, server A and server B are servers.
21
+
When you move a database to a new server (like in a migration or restore), the database users are moved, but their corresponding server-level logins might not exist on the new instance, creating orphaned users. Transferring login and passwords is crucial for maintaining security and access continuity.
21
22
22
23
After you move a database from a SQL Server instance on server A to a SQL Server instance on server B, users might be unable to log in to the database server on server B. Additionally, users might receive the following error message:
23
24
24
25
> Login failed for user '**MyUser**'. (Microsoft SQL Server, Error: 18456)
25
26
26
27
This problem occurs because the logins from the SQL Server instance on server A don't exist in the SQL Server instance on server B.
27
28
28
-
Keep in mind that error 18456 occurs for many other reasons. For more information on these causes and their resolutions, see [MSSQLSERVER_18456](/sql/relational-databases/errors-events/mssqlserver-18456-database-engine-error).
29
+
Error 18456 can also occur for several other reasons. For more information on the various causes and their resolutions, see [MSSQLSERVER_18456](/sql/relational-databases/errors-events/mssqlserver-18456-database-engine-error).
29
30
30
31
## Steps to transfer logins between SQL Server instances
31
32
32
33
To transfer the logins, use one of the following methods, as appropriate for your situation.
33
34
34
-
### Method 1: Generate scripts via SSMS on the source server and manually reset passwords for SQL Server logins on the destination server
35
+
### Method: Generate scripts via SSMS on the source server and manually reset passwords for SQL Server logins on the destination server
35
36
36
-
You can generate login scripts in SQL Server Management Studio (SSMS) by using the [Generate Scripts option for a database](/sql/ssms/tutorials/scripting-ssms#script-a-database-by-using-the-generate-scripts-option).
37
+
You can generate login scripts in SQL Server Management Studio (SSMS) by using the [Generate Scripts option for a database](/sql/ssms/tutorials/scripting-ssms#script-a-database-by-using-the-generate-scripts-option).
37
38
38
39
To generate scripts via SSMS on the source server and manually reset passwords for SQL Server logins on the destination server, follow these steps:
39
40
@@ -51,12 +52,12 @@ To generate scripts via SSMS on the source server and manually reset passwords f
51
52
`/* For security reasons the login is created disabled and with a random password. */`
52
53
53
54
> [!NOTE]
54
-
> This indicates that the SQL Server Authentication logins are generated with a random password and are disabled by default. You need to reset the password and re-enable these logins on the destination server.
55
+
> This comment indicates that the SQL Server Authentication logins are generated with a random password and are disabled by default. You need to reset the password and re-enable these logins on the destination server.
55
56
56
57
1. Apply the login script from the larger generated script to the destination SQL Server.
57
58
1. For any SQL Server Authentication logins, reset the password on the destination SQL Server and re-enable those logins.
58
59
59
-
### Method 2: Transfer logins and passwords to the destination server (Server B) using scripts generated on the source server (Server A)
60
+
### Method: Transfer logins and passwords to the destination server (Server B) by using scripts generated on the source server (Server A)
60
61
61
62
1. Create stored procedures that will help generate necessary scripts to transfer logins and their passwords. To do so, connect to Server A using SQL Server Management Studio (SSMS) or any other client tool and run the following script:
62
63
@@ -275,7 +276,7 @@ To generate scripts via SSMS on the source server and manually reset passwords f
275
276
> [!NOTE]
276
277
> This script creates two stored procedures in the master database. The procedures are named **sp_hexadecimal**and**sp_help_revlogin**.
277
278
278
-
1. In the SSMS query editor, select the **[Results to Text](/sql/ssms/f1-help/database-engine-query-editor-sql-server-management-studio)** option.
279
+
1. In the SSMS query editor, select the [Results to Text](/sql/ssms/f1-help/database-engine-query-editor-sql-server-management-studio) option.
279
280
280
281
1. Run the following statement in the same or a new query window:
0 commit comments