Skip to content

Commit 337b266

Browse files
Merge pull request #252375 from ajithkr-ms/updatecustomsqlaccountscript
Updated the custom login creation script
2 parents d5d3b5d + 2d0a3cb commit 337b266

File tree

3 files changed

+33
-24
lines changed

3 files changed

+33
-24
lines changed

articles/migrate/migrate-support-matrix-hyper-v.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ The following are sample scripts for creating a login and provisioning it with t
107107
```sql
108108
-- Create a login to run the assessment
109109
use master;
110-
-- If a SID needs to be specified, add here
111-
DECLARE @SID NVARCHAR(MAX) = N'';
110+
DECLARE @SID NVARCHAR(MAX) = N'';
112111
CREATE LOGIN [MYDOMAIN\MYACCOUNT] FROM WINDOWS;
113112
SELECT @SID = N'0x'+CONVERT(NVARCHAR, sid, 2) FROM sys.syslogins where name = 'MYDOMAIN\MYACCOUNT'
114113
IF (ISNULL(@SID,'') != '')
@@ -165,7 +164,10 @@ The following are sample scripts for creating a login and provisioning it with t
165164
```sql
166165
-- Create a login to run the assessment
167166
use master;
168-
-- If a SID needs to be specified, add here
167+
-- NOTE: SQL instances that host replicas of Always On Availability Groups must use the same SID with SQL login.
168+
-- After the account is created in one of the member instances, copy the SID output from the script and include
169+
-- this value when executing against the remaining replicas.
170+
-- When the SID needs to be specified, add the value to the @SID variable definition below.
169171
DECLARE @SID NVARCHAR(MAX) = N'';
170172
IF (@SID = N'')
171173
BEGIN
@@ -174,13 +176,14 @@ The following are sample scripts for creating a login and provisioning it with t
174176
END
175177
ELSE
176178
BEGIN
177-
CREATE LOGIN [evaluator]
178-
WITH PASSWORD = '<provide a strong password>'
179-
, SID = @SID
179+
DECLARE @SQLString NVARCHAR(500) = 'CREATE LOGIN [evaluator]
180+
WITH PASSWORD = ''<provide a strong password>''
181+
, SID = '+@SID
182+
EXEC SP_EXECUTESQL @SQLString
180183
END
181184
SELECT @SID = N'0x'+CONVERT(NVARCHAR, sid, 2) FROM sys.syslogins where name = 'evaluator'
182185
IF (ISNULL(@SID,'') != '')
183-
PRINT N'Created login [evaluator] with SID = '+@SID
186+
PRINT N'Created login [evaluator] with SID = '''+ @SID +'''. If this instance hosts any Always On Availability Group replica, use this SID value when executing the script against the instances hosting the other replicas'
184187
ELSE
185188
PRINT N'Login creation failed'
186189
GO

articles/migrate/migrate-support-matrix-physical.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,7 @@ The following are sample scripts for creating a login and provisioning it with t
160160
```sql
161161
-- Create a login to run the assessment
162162
use master;
163-
-- If a SID needs to be specified, add here
164-
DECLARE @SID NVARCHAR(MAX) = N'';
163+
DECLARE @SID NVARCHAR(MAX) = N'';
165164
CREATE LOGIN [MYDOMAIN\MYACCOUNT] FROM WINDOWS;
166165
SELECT @SID = N'0x'+CONVERT(NVARCHAR, sid, 2) FROM sys.syslogins where name = 'MYDOMAIN\MYACCOUNT'
167166
IF (ISNULL(@SID,'') != '')
@@ -218,7 +217,10 @@ The following are sample scripts for creating a login and provisioning it with t
218217
```sql
219218
-- Create a login to run the assessment
220219
use master;
221-
-- If a SID needs to be specified, add here
220+
-- NOTE: SQL instances that host replicas of Always On Availability Groups must use the same SID for the SQL login.
221+
-- After the account is created in one of the members, copy the SID output from the script and include this value
222+
-- when executing against the remaining replicas.
223+
-- When the SID needs to be specified, add the value to the @SID variable definition below.
222224
DECLARE @SID NVARCHAR(MAX) = N'';
223225
IF (@SID = N'')
224226
BEGIN
@@ -227,13 +229,14 @@ The following are sample scripts for creating a login and provisioning it with t
227229
END
228230
ELSE
229231
BEGIN
230-
CREATE LOGIN [evaluator]
231-
WITH PASSWORD = '<provide a strong password>'
232-
, SID = @SID
232+
DECLARE @SQLString NVARCHAR(500) = 'CREATE LOGIN [evaluator]
233+
WITH PASSWORD = ''<provide a strong password>''
234+
, SID = '+@SID
235+
EXEC SP_EXECUTESQL @SQLString
233236
END
234-
SELECT @SID = N'0x'+CONVERT(NVARCHAR, sid, 2) FROM sys.syslogins where name = 'evaluator'
237+
SELECT @SID = N'0x'+CONVERT(NVARCHAR(35), sid, 2) FROM sys.syslogins where name = 'evaluator'
235238
IF (ISNULL(@SID,'') != '')
236-
PRINT N'Created login [evaluator] with SID = '+@SID
239+
PRINT N'Created login [evaluator] with SID = '''+ @SID +'''. If this instance hosts any Always On Availability Group replica, use this SID value when executing the script against the instances hosting the other replicas'
237240
ELSE
238241
PRINT N'Login creation failed'
239242
GO

articles/migrate/migrate-support-matrix-vmware.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ The following are sample scripts for creating a login and provisioning it with t
106106
```sql
107107
-- Create a login to run the assessment
108108
use master;
109-
-- If a SID needs to be specified, add here
110-
DECLARE @SID NVARCHAR(MAX) = N'';
109+
DECLARE @SID NVARCHAR(MAX) = N'';
111110
CREATE LOGIN [MYDOMAIN\MYACCOUNT] FROM WINDOWS;
112111
SELECT @SID = N'0x'+CONVERT(NVARCHAR, sid, 2) FROM sys.syslogins where name = 'MYDOMAIN\MYACCOUNT'
113112
IF (ISNULL(@SID,'') != '')
@@ -164,22 +163,26 @@ The following are sample scripts for creating a login and provisioning it with t
164163
```sql
165164
-- Create a login to run the assessment
166165
use master;
167-
-- If a SID needs to be specified, add here
168-
DECLARE @SID NVARCHAR(MAX) = N'';
166+
-- NOTE: SQL instances that host replicas of Always On Availability Groups must use the same SID for the SQL login.
167+
-- After the account is created in one of the members, copy the SID output from the script and include this value
168+
-- when executing against the remaining replicas.
169+
-- When the SID needs to be specified, add the value to the @SID variable definition below.
170+
DECLARE @SID NVARCHAR(MAX) = N'';
169171
IF (@SID = N'')
170172
BEGIN
171173
CREATE LOGIN [evaluator]
172174
WITH PASSWORD = '<provide a strong password>'
173175
END
174176
ELSE
175177
BEGIN
176-
CREATE LOGIN [evaluator]
177-
WITH PASSWORD = '<provide a strong password>'
178-
, SID = @SID
178+
DECLARE @SQLString NVARCHAR(500) = 'CREATE LOGIN [evaluator]
179+
WITH PASSWORD = ''<provide a strong password>''
180+
, SID = ' + @SID
181+
EXEC SP_EXECUTESQL @SQLString
179182
END
180-
SELECT @SID = N'0x'+CONVERT(NVARCHAR, sid, 2) FROM sys.syslogins where name = 'evaluator'
183+
SELECT @SID = N'0x'+CONVERT(NVARCHAR(100), sid, 2) FROM sys.syslogins where name = 'evaluator'
181184
IF (ISNULL(@SID,'') != '')
182-
PRINT N'Created login [evaluator] with SID = '+@SID
185+
PRINT N'Created login [evaluator] with SID = '''+ @SID +'''. If this instance hosts any Always On Availability Group replica, use this SID value when executing the script against the instances hosting the other replicas'
183186
ELSE
184187
PRINT N'Login creation failed'
185188
GO

0 commit comments

Comments
 (0)