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
This article describes how to transfer the logins and passwords between different instances of Microsoft SQL Server. The instances might be on the same server or on different servers, and their versions might differ.
20
+
This article describes how to transfer the logins and passwords between different instances of Microsoft SQL Server. The instances might be on the same server or different servers, and their versions might differ.
21
21
22
-
## Why transfer logins between SQL Servers?
22
+
## Why transfer logins between SQL Server instances?
23
23
24
24
In this article, server A and server B are servers.
25
25
26
26
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:
27
27
28
28
> Login failed for user '**MyUser**'. (Microsoft SQL Server, Error: 18456)
29
29
30
-
This problem occurs because the logins from SQL Server instance on server A don't exist in the SQL Server instance on server B.
30
+
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.
31
31
32
32
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).
33
33
34
34
## Steps to transfer the logins
35
35
36
36
To transfer the logins, use one of the following methods, as appropriate for your situation.
37
37
38
-
### Method 1: Generate scripts via SSMS on source server and manually reset passwords for SQL Server logins on destination server
38
+
### Method 1: Generate scripts via SSMS on the source server and manually reset passwords for SQL Server logins on the destination server
39
39
40
40
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).
41
41
42
-
To generate scripts via SSMS on source server and manually reset passwords for SQL Server logins on destination server, follow these steps:
42
+
To generate scripts via SSMS on the source server and manually reset passwords for SQL Server logins on the destination server, follow these steps:
43
43
44
44
1. Connect to server A that's hosting the source SQL Server.
45
45
1. Expand the **Databases** node.
46
-
1. Right-click on any user database and select **Tasks** > **Generate Scripts**.
47
-
1. The **Introduction** page opens. Select **Next** to open the **Chose Objects** page. Select **Script entire database and all database objects**.
46
+
1. Right-click any user database and select **Tasks** > **Generate Scripts**.
47
+
1. The **Introduction** page opens. Select **Next** to open the **Choose Objects** page. Select **Script entire database and all database objects**.
48
48
1. Select **Next** to open the **Set Scripting Options** page.
49
49
1. Select the **Advanced** button for Script Login options.
50
50
1. In the **Advanced** list, find **Script Logins**, set the option to **True** and select **OK**.
51
51
1. Back to **Set Scripting Options** under **Select how scripts should be saved** and select **Open in new query window**.
52
-
1. Select **Next** twice, then select **Finish**.
52
+
1. Select **Next** twice, and then select **Finish**.
53
53
1. Find the section in the script that contains logins. Typically, the generated script contains text with the following comment at the beginning of this section:
54
54
55
55
`/* For security reasons the login is created disabled and with a random password. */`
@@ -60,7 +60,7 @@ To generate scripts via SSMS on source server and manually reset passwords for S
60
60
1. Apply the login script from the larger generated script to the destination SQL Server.
61
61
1. For any SQL Server Authentication logins, reset the password on the destination SQL Server and re-enable those logins.
62
62
63
-
### Method 2: Transfer logins and passwords to destination server (Server B) using scripts generated on source server (Server A)
63
+
### Method 2: Transfer logins and passwords to the destination server (Server B) using scripts generated on the source server (Server A)
64
64
65
65
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:
66
66
@@ -302,25 +302,25 @@ Review the following information before you run the output script on the instanc
302
302
303
303
-`VERSION_SHA1`: This hash is generated by using the SHA1 algorithm and is used in SQL Server 2000 through SQL Server 2008 R2.
304
304
-`VERSION_SHA2`: This hash is generated by using the SHA2 512 algorithm and is used in SQL Server 2012and later versions.
305
-
-In the output script, the logins are created by using the encrypted password. This is because of the HASHED argument in the `CREATE LOGIN` statement. This argument specifies that the password that is entered after the PASSWORD argument is already hashed.
305
+
-In the output script, the logins are created by using the encrypted password. This is because of the `HASHED` argument in the `CREATE LOGIN` statement. This argument specifies that the password that is entered after the `PASSWORD` argument is already hashed.
306
306
307
-
### How to handle change of domains
307
+
### How to handle the change of domains
308
308
309
309
Are your source and destination servers in different domains? Review the output script carefully. If server A and server B are in different domains, you have to change the output script. Then, you have to replace the original domain name by using the new domain name in the `CREATE LOGIN` statements. The integrated logins that are granted access in the new domain don't have the same SID as the logins in the original domain. Therefore, users are orphaned from these logins. For more information about how to resolve these orphaned users, see [Troubleshoot orphaned users (SQL Server)](/sql/sql-server/failover-clusters/troubleshoot-orphaned-users-sql-server) and [ALTER USER](/sql/t-sql/statements/alter-user-transact-sql).
310
310
311
311
If server A and server B are in the same domain, the same SID is used. Therefore, users are unlikely to be orphaned.
312
312
313
-
### Permissions to view and select all login
313
+
### Permissions to view and select all logins
314
314
315
315
By default, only a member of the sysadmin fixed server role can run a `SELECT` statement from the `sys.server_principals` view. Unless a member of the sysadmin fixed server role grants the necessary permissions to the users, the users can't create or run the output script.
316
316
317
317
### Default database setting isn't scripted and transferred
318
318
319
319
The steps in this article don't transfer the default database information for a particular login. This is because the default database might not always exist on server B. To define the default database for a login, use the `ALTER LOGIN` statement by passing in the login name and the default database as arguments.
320
320
321
-
### How to deal with different sort orders between source and destination SQL Server
321
+
### How to deal with different sort orders between the source and destination servers
322
322
323
-
There could be differences in sort orders between the source and destination servers or they could be the same. Here's how each scenario can be addressed:
323
+
There might differences in sort orders between the source and destination servers, or they might the same. Here's how each scenario can be addressed:
324
324
325
325
-**Case-insensitive server A and case-sensitive server B**: The sort order of server A might be case-insensitive, and the sort order of server B might be case-sensitive. In this case, users must type the passwords in all uppercase letters after you transfer the logins and the passwords to the instance on server B.
326
326
-**Case-sensitive server A and case-insensitive server B:** The sort order of server A might be case-sensitive, and the sort order of server B might be case-insensitive. In this case, users can't log in by using the logins and the passwords that you transfer to the instance on server B unless one of the following conditions is true:
@@ -332,7 +332,7 @@ There could be differences in sort orders between the source and destination ser
332
332
333
333
### How to deal with logins already existing on the destination server
334
334
335
-
The script is designed to check if the login exists on the destination server. It creates a login only if it doesn't exist on the destination server. However, if you receive the following error message when you run the output script on the instance on server B, you have to manually resolve it by following the steps in this section.
335
+
The script is designed to check if the login exists on the destination serverand create a login only if it doesn't. However, if you receive the following error message when you run the output script on the instance on server B, you have to manually resolve it by following the steps in this section.
336
336
337
337
> Msg 15025, Level 16, State 1, Line 1
338
338
> The server principal '**MyLogin**' already exists.
@@ -350,7 +350,7 @@ To manually resolve the issue, follow these steps:
350
350
351
351
Starting in SQL Server 2005, the SID for a login is used to manage database-level access. Occasionally, a login might have different SIDs when mapped to users in different databases. This issue can occur if databases are manually combined from different servers. In such cases, the login can only access the database where the database principal's SID matches the SID in the `sys.server_principals` view. To resolve this issue, manually remove the database user with the mismatched SID using the [DROP USER](/sql/t-sql/statements/drop-user-transact-sql) statement. Then, add the user again with the `CREATE USER` statement and map it to the correct login (server principal).
352
352
353
-
For more information and to distinguish serverfrom database principals, see [CREATE USER](/sql/t-sql/statements/create-user-transact-sql) and [CREATE LOGIN.](/sql/t-sql/statements/create-login-transact-sql).
353
+
For more information and to distinguish serversfrom database principals, see [CREATE USER](/sql/t-sql/statements/create-user-transact-sql) and [CREATE LOGIN](/sql/t-sql/statements/create-login-transact-sql).
0 commit comments