Skip to main content

Notifications

Microsoft Dynamics GP (Archived)

Capture Logins sql script from KB878449 - link broken

Posted on by Microsoft Employee

Hello all,


I'm working on a conversion to get us out of the Middle Ages and into the new millennium by upgrading from GP10.0 to GP2015.

Along the way we will be switching servers.  In my test conversion I have already hit the road block described here:

https://community.dynamics.com/gp/f/32/t/42384

Obviously it seems that the first step is to do a proper server change as documented in KB878449.  The only issue is that when I click the link for the Capture_Logins.sql file here, I get a 404 page not found error.  

https://mbs.microsoft.com/files/customer/gp/downloads/servicepacks/help878449_capture_logins.sql

Does anyone know the correct link?  Or can you hook me up with the right script?  I saw some discussion about if the server is SQL 2012 or newer, and in my case the originating server is SQL 2005.

Thank you,

Brett Saundry

Systems Analyst/Developer

Corporate Applications Support | SS&C Technologies, Inc.

*This post is locked for comments

  • ImAPilot Profile Picture
    ImAPilot 70 on at
    RE: Capture Logins sql script from KB878449 - link broken

    Curious if anyone has used this successfully with SQL 2019 or 2022?  

    I tried using it during a server migration on SQL2019 a few years back, and didn't seem to work.  I was under a time crunch at the time, so just reset the users passwords and moved on with my day. I'm trying to roll out a new SQL 2022 server, and would really like to keep the users on the same password this time, but the script doesn't seem to be working. I have used it many times in the past, but that was probably in the SQL 2012 days.

    To test, I have made sure to use the same ODBC connection (same name and case), I just changed the connection string from sqlA to sqlB, but no luck.

    I also found an updated version of the script here, but both versions generate the same encoded string and hash.

    learn.microsoft.com/.../transfer-logins-passwords-between-instances

    Any ideas?

  • David Musgrave MVP GPUG All Star Legend Moderator Profile Picture
    David Musgrave MVP ... 13,915 Most Valuable Professional on at
    RE: Capture Logins sql script from KB878449 - link broken

    Hi Joe

    Please contact sales@Mekorma.com. They are my distribution partner and will be able to help.

    Thanks

    David

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Capture Logins sql script from KB878449 - link broken

    Hi David

    Been trying to buy GP Power Tools for a month now.  Can't seem to get in invoice from anyone to get reg keys.  Can you help out?

    Thanks

    Joe Guyton

  • Suggested answer
    David Musgrave MVP GPUG All Star Legend Moderator Profile Picture
    David Musgrave MVP ... 13,915 Most Valuable Professional on at
    RE: Capture Logins sql script from KB878449 - link broken

    Hi guys

    Two points

    1) The  script in the kb was broken, I fixed it in my blog post.

    blogs.msdn.microsoft.com/.../capture-logins-script-from-kb-878449-generates-invalid-object-name-error

    Looks like Harry has posted the script I fixed.

    2) GP Power Tools' Database Validation fixes this issue in a much simpler, faster and more secure way. In just a few clicks, it can fix this and many other issues with synchronizing users and companies with SQL logins, users and databases.

    http://WinthropDC.com/GPPT

    David

  • Verified answer
    Redbeard Profile Picture
    Redbeard 12,931 on at
    RE: Capture Logins sql script from KB878449 - link broken

    For Posterity

    /************************************************************************************************

    *

    * Purpose: To capture all the SQL Server logins with the binary password regardless of SQL version.  

    * Script is compatiable with SQL 7 / 2000 / 2005/ 2008 / 2008R2 / 2012.

    * Need to save the results to a text file and run within a new query window.

    *

    * Created Date: Inital - 01/13/2006

    *

    * Revsions: 01/15/2006 - Made some formatting changes to the output text.

    * 01/16/2006 - Made syntax change to account for Binary version of SQL Server.

    * 01/16/2006 - Change version SQL version check because of syntax differences between SQL 2000 and 2005 with @@version.

    * 04/10/2007 - Made change to deal with user names that begin with numbers instead of characters.

    *           11/14/2008 - Made syntax change to update for SQL 2008

       *           08/26/2010 - Made syntax change to update for SQL 2008 R2    

    * 12/20/2012 - Made syntax change to update for SQL 2012

    * 04/30/2014 - Changed version number check to handle SQL 2012 SP1 (and all future versions)

    *

    ************************************************************************************************/

    USE master

    GO

    IF OBJECT_ID ('sp_hexadecimal') IS NOT NULL

     DROP PROCEDURE sp_hexadecimal

    GO

    CREATE PROCEDURE sp_hexadecimal

    @binvalue varbinary(256),

    @hexvalue varchar(256) OUTPUT

    AS

    DECLARE @charvalue varchar(256)

    DECLARE @i int

    DECLARE @length int

    DECLARE @hexstring char(16)

    SELECT @charvalue = '0x'

    SELECT @i = 1

    SELECT @length = DATALENGTH (@binvalue)

    SELECT @hexstring = '0123456789ABCDEF'

    WHILE (@i <= @length)

    BEGIN

     DECLARE @tempint int

     DECLARE @firstint int

     DECLARE @secondint int

     SELECT @tempint = CONVERT(int, SUBSTRING(@binvalue,@i,1))

     SELECT @firstint = FLOOR(@tempint/16)

     SELECT @secondint = @tempint - (@firstint*16)

     SELECT @charvalue = @charvalue +

    SUBSTRING(@hexstring, @firstint+1, 1) +

    SUBSTRING(@hexstring, @secondint+1, 1)

     SELECT @i = @i + 1

    END

    SELECT @hexvalue = @charvalue

    GO

    IF OBJECT_ID ('sp_help_revlogin') IS NOT NULL

     DROP PROCEDURE sp_help_revlogin

    GO

    CREATE PROCEDURE sp_help_revlogin @login_name sysname = NULL AS

    DECLARE @name    sysname

    DECLARE @xstatus int

    DECLARE @binpwd  varbinary (256)

    DECLARE @txtpwd  sysname

    DECLARE @tmpstr  varchar (256)

    DECLARE @SID_varbinary varbinary(85)

    DECLARE @SID_string varchar(256)

    IF (@login_name IS NULL)

     DECLARE login_curs CURSOR FOR

    SELECT sid, name, xstatus, password FROM master..sysxlogins

    WHERE srvid IS NULL AND name <> 'sa'

    ELSE

     DECLARE login_curs CURSOR FOR

    SELECT sid, name, xstatus, password FROM master..sysxlogins

    WHERE srvid IS NULL AND name = @login_name

    OPEN login_curs

    FETCH NEXT FROM login_curs INTO @SID_varbinary, @name, @xstatus, @binpwd

    IF (@@fetch_status = -1)

    BEGIN

     PRINT 'No login(s) found.'

     CLOSE login_curs

     DEALLOCATE login_curs

     RETURN -1

    END

    SET @tmpstr = '/* sp_help_revlogin script '

    PRINT @tmpstr

    SET @tmpstr = '** Generated '

     + CONVERT (varchar, GETDATE()) + ' on ' + @@SERVERNAME + ' */'

    PRINT @tmpstr

    PRINT ''

    PRINT 'DECLARE @pwd sysname'

    WHILE (@@fetch_status <> -1)

    BEGIN

     IF (@@fetch_status <> -2)

     BEGIN

    PRINT ''

    SET @tmpstr = '-- Login: ' + @name

    PRINT @tmpstr

    IF (@xstatus & 4) = 4

    BEGIN -- NT authenticated account/group

     IF (@xstatus & 1) = 1

     BEGIN -- NT login is denied access

    SET @tmpstr = 'EXEC master..sp_denylogin ''' + @name + ''''

    PRINT @tmpstr

     END

     ELSE BEGIN -- NT login has access

    SET @tmpstr = 'EXEC master..sp_grantlogin ''' + @name + ''''

    PRINT @tmpstr

     END

    END

    ELSE BEGIN -- SQL Server authentication

     IF (@binpwd IS NOT NULL)

     BEGIN -- Non-null password

    EXEC sp_hexadecimal @binpwd, @txtpwd OUT

    IF (@xstatus & 2048) = 2048

     SET @tmpstr = 'SET @pwd = CONVERT (varchar(256), ' + @txtpwd + ')'

    ELSE

     SET @tmpstr = 'SET @pwd = CONVERT (varbinary(256), ' + @txtpwd + ')'

    PRINT @tmpstr

    EXEC sp_hexadecimal @SID_varbinary,@SID_string OUT

    SET @tmpstr = 'EXEC master..sp_addlogin ''' + @name + ''

     + ''', @pwd, @sid = ' + @SID_string + ', @encryptopt = '

     END

     ELSE BEGIN

    -- Null password

    EXEC sp_hexadecimal @SID_varbinary,@SID_string OUT

    SET @tmpstr = 'EXEC master..sp_addlogin ''' + @name + ''

     + ''', NULL, @sid = ' + @SID_string + ', @encryptopt = '

     END

     IF (@xstatus & 2048) = 2048

    -- login upgraded from 6.5

    SET @tmpstr = @tmpstr + '''skip_encryption_old'''

     ELSE

    SET @tmpstr = @tmpstr + '''skip_encryption'''

     PRINT @tmpstr

    END

     END

     FETCH NEXT FROM login_curs INTO @SID_varbinary, @name, @xstatus, @binpwd

     END

    CLOSE login_curs

    DEALLOCATE login_curs

    RETURN 0

    GO

    IF OBJECT_ID ('seeMigrateSQLLogins') IS NOT NULL

     DROP PROCEDURE seeMigrateSQLLogins

    GO

    create procedure seeMigrateSQLLogins @login_name sysname = NULL

    as

    DECLARE @name sysname

    DECLARE @type varchar (1)

    DECLARE @hasaccess int

    DECLARE @denylogin int

    DECLARE @is_disabled int

    DECLARE @PWD_varbinary  varbinary (256)

    DECLARE @PWD_string  varchar (514)

    DECLARE @SID_varbinary varbinary (85)

    DECLARE @SID_string varchar (514)

    DECLARE @tmpstr  varchar (1024)

    DECLARE @is_policy_checked varchar (3)

    DECLARE @is_expiration_checked varchar (3)

    DECLARE @defaultdb sysname

    IF (@login_name IS NULL)

     DECLARE login_curs CURSOR FOR

     SELECT p.sid, p.name, p.type, p.is_disabled, p.default_database_name, l.hasaccess, l.denylogin FROM

    sys.server_principals p LEFT JOIN sys.syslogins l

     ON ( l.name = p.name ) WHERE p.type IN ( 'S', 'G', 'U' ) AND p.name <> 'sa'

    ELSE

     DECLARE login_curs CURSOR FOR

     SELECT p.sid, p.name, p.type, p.is_disabled, p.default_database_name, l.hasaccess, l.denylogin FROM

    sys.server_principals p LEFT JOIN sys.syslogins l

     ON ( l.name = p.name ) WHERE p.type IN ( 'S', 'G', 'U' ) AND p.name = @login_name

    OPEN login_curs

    FETCH NEXT FROM login_curs INTO @SID_varbinary, @name, @type, @is_disabled, @defaultdb, @hasaccess, @denylogin

    IF (@@fetch_status = -1)

    BEGIN

     PRINT 'No login(s) found.'

     CLOSE login_curs

     DEALLOCATE login_curs

     RETURN -1

    END

    SET @tmpstr = '/* sp_help_revlogin script '

    PRINT @tmpstr

    SET @tmpstr = '** Generated ' + CONVERT (varchar, GETDATE()) + ' on ' + @@SERVERNAME + ' */'

    PRINT @tmpstr

    PRINT ''

    WHILE (@@fetch_status <> -1)

    BEGIN

     IF (@@fetch_status <> -2)

     BEGIN

    PRINT ''

    SET @tmpstr = '-- Login: ' + @name

    PRINT @tmpstr

    IF (@type IN ( 'G', 'U'))

    BEGIN -- NT authenticated account/group

     SET @tmpstr = 'CREATE LOGIN ' + QUOTENAME( @name ) + ' FROM WINDOWS WITH DEFAULT_DATABASE = [' + @defaultdb + ']'

    END

    ELSE BEGIN -- SQL Server authentication

    -- obtain password and sid

    SET @PWD_varbinary = CAST( LOGINPROPERTY( @name, 'PasswordHash' ) AS varbinary (256) )

    EXEC sp_hexadecimal @PWD_varbinary, @PWD_string OUT

    EXEC sp_hexadecimal @SID_varbinary,@SID_string OUT

    -- obtain password policy state

    SELECT @is_policy_checked = CASE is_policy_checked WHEN 1 THEN 'ON' WHEN 0 THEN 'OFF' ELSE NULL END FROM sys.sql_logins WHERE name = @name

    SELECT @is_expiration_checked = CASE is_expiration_checked WHEN 1 THEN 'ON' WHEN 0 THEN 'OFF' ELSE NULL END FROM sys.sql_logins WHERE name = @name

    SET @tmpstr = 'CREATE LOGIN ' + QUOTENAME( @name ) + ' WITH PASSWORD = ' + @PWD_string + ' HASHED, SID = ' + @SID_string + ', DEFAULT_DATABASE = [' + @defaultdb + ']'

    IF ( @is_policy_checked IS NOT NULL )

    BEGIN

     SET @tmpstr = @tmpstr + ', CHECK_POLICY = ' + @is_policy_checked

    END

    IF ( @is_expiration_checked IS NOT NULL )

    BEGIN

     SET @tmpstr = @tmpstr + ', CHECK_EXPIRATION = ' + @is_expiration_checked

    END

    END

    IF (@denylogin = 1)

    BEGIN -- login is denied access

     SET @tmpstr = @tmpstr + '; DENY CONNECT SQL TO ' + QUOTENAME( @name )

    END

    ELSE IF (@hasaccess = 0)

    BEGIN -- login exists but does not have access

     SET @tmpstr = @tmpstr + '; REVOKE CONNECT SQL TO ' + QUOTENAME( @name )

    END

    IF (@is_disabled = 1)

    BEGIN -- login is disabled

     SET @tmpstr = @tmpstr + '; ALTER LOGIN ' + QUOTENAME( @name ) + ' DISABLE'

    END

    PRINT @tmpstr

     END

     FETCH NEXT FROM login_curs INTO @SID_varbinary, @name, @type, @is_disabled, @defaultdb, @hasaccess, @denylogin

      END

    CLOSE login_curs

    DEALLOCATE login_curs

    RETURN 0

    GO

    if (ltrim(substring(@@version, patindex('%[0-9].[0-9]%', @@version)-1,4)) in ('9.0','10.0','10.5','11.0') )

    Begin

    exec seeMigrateSQLLogins

    End

    Else

    begin

    exec sp_help_revlogin

    End

    IF OBJECT_ID ('sp_hexadecimal') IS NOT NULL

     DROP PROCEDURE sp_hexadecimal

    GO

    IF OBJECT_ID ('sp_help_revlogin') IS NOT NULL

     DROP PROCEDURE sp_help_revlogin

    GO

    IF OBJECT_ID ('seeMigrateSQLLogins') IS NOT NULL

     DROP PROCEDURE seeMigrateSQLLogins

    GO

    /* End Script */

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Capture Logins sql script from KB878449 - link broken

    Could it be some sort of portal permissions issue, the re-direct just takes me to a 404 not found page:

    404.JPG

  • Richard Wheeler Profile Picture
    Richard Wheeler 75,730 on at

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans