How to transfer logins and the passwords between SQL Servers PDF Print E-mail

A step by step artcile which describes how to transfer logins and the passwords between SQL Servers. This is a very good article for migrating the whole sqlserver and migrating databases between sql servers.

Method 1 (Transer logins & Passwords between two SQLServer 2000 Versions)

1) Take the script(sp_help_revlogin) from the below link & execute the script in the source sql server.

http://support.microsoft.com/kb/246133 (Opt for Method 1(servers that are running SQL Server 2000))

Modify some lines as shown in below only if you are moving/migrating only selected database(s) else go to step2

ie;

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

As

DECLARE login_curs CURSOR FOR
    SELECT a.sid, a.name, a.xstatus, a.password FROM master..sysxlogins a join Migrating_UserDB..sysusers b on a.sid=b.sid
    WHERE srvid IS NULL AND a.name 'sa'
ELSE
  DECLARE login_curs CURSOR FOR
    SELECT a.sid, a.name, a.xstatus, a.password FROM master..sysxlogins a join Migrating_UserDB..sysusers b on a.sid=b.sid
    WHERE srvid IS NULL AND a.name = @login_name


Note: Here we are joining the master with Migrating_UserDB to get only the logins, users specific to the unser database which we are migrating/moving. Make sure to change the necessary changes(As shown above) in the script


2) Copy the result of the above procedure & save it
3) Move the needed database(s) to destination server by backup/restore or attach/detach
4) Exec sp_change_users_login 'Report' in the restored user db to find the orphan users.
5) Exec the above saved result from step1 in the destination server, in the restored
    user database.
6) Once again Exec sp_change_users_login 'Report' in the restored user db to find the  orphan users.
7) If any more orphan users are existing run the below script to link the orphan users
    to the newly created logins from the result script of step1

-------------- script to correct login IDs --------
declare @login sysname
declare log_curs cursor for
select name from sysusers where upper(name) 'DBO' and status=2

open log_curs
fetch next from log_curs into @login
WHILE (@@FETCH_STATUS -1)
BEGIN
   IF (@@FETCH_STATUS -2)
   BEGIN  
      exec sp_change_users_login 'Update_One', @login, @login
      Print 'Login Updated: "' + @login + '".'
   END
   FETCH NEXT FROM log_curs INTO @login
END
CLOSE log_curs
DEALLOCATE log_curs
---------------------------------------------------


8) Once again Exec sp_change_users_login 'Report' in the restored user db to find the  orphan users. Make sure there are no orphan users.

Method 2 (Transer logins & Passwords between SQLServer 2000 & SQLServer 2005)

1) Take the script(sp_help_revlogin) from the below link & execute the script in the source sql server.

http://support.microsoft.com/kb/246133 (Opt for Method 2(from SQL Server 2000 to SQL Server 2005))

Modify some lines as shown in below only if you are moving/migrating only selected database(s) else go to step2

ie;

DECLARE login_curs CURSOR STATIC FOR
 SELECT sid, [name], xstatus, password, isnull(db_name(dbid), 'master')
 FROM master.dbo.sysxlogins
 WHERE srvid IS NULL AND [name] 'sa'
ELSE
DECLARE login_curs CURSOR FOR
 SELECT sid, [name], xstatus, password, isnull(db_name(dbid), 'master')
 FROM master.dbo.sysxlogins
 WHERE srvid IS NULL AND [name] = @login_name

As

DECLARE login_curs CURSOR STATIC FOR
 SELECT a.sid, [a.name], a.xstatus, a.password, isnull(db_name(dbid), 'master')
 FROM master.dbo.sysxlogins a join Migrating_UserDB..sysusers b on a.sid=b.sid
 WHERE srvid IS NULL AND [name] 'sa'
ELSE
DECLARE login_curs CURSOR FOR
 SELECT a.sid, [a.name], a.xstatus, a.password, isnull(db_name(dbid), 'master')
 FROM master.dbo.sysxlogins a join Migrating_UserDB..sysusers b on a.sid=b.sid
 WHERE srvid IS NULL AND [name] = @login_name


Note: Here we are joining the master with Migrating_UserDB to get only the logins, users specific to the unser database which we are migrating/moving. Make sure to change the necessary changes in the script


2) Copy the result of the above procedure & save it
3) Move the needed database to destination server by backup/restore or attach/detach
4) Exec sp_change_users_login 'Report' in the restored user db to find the orphan users.
5) Exec the above saved result from step1 in the destination server, in the restored
    user database.
6)  Once again Exec sp_change_users_login 'Report' in the restored user db to find the  orphan users.
7) If any more orphan users are existing run the below script to link the orphan users
    to the newly created logins from the result script of step1

-------------- script to correct login IDs --------
declare @login sysname
declare log_curs cursor for
select name from sysusers where upper(name) 'DBO' and status=2

open log_curs
fetch next from log_curs into @login
WHILE (@@FETCH_STATUS -1)
BEGIN
   IF (@@FETCH_STATUS -2)
   BEGIN  
      exec sp_change_users_login 'Update_One', @login, @login
      Print 'Login Updated: "' + @login + '".'
   END
   FETCH NEXT FROM log_curs INTO @login
END
CLOSE log_curs
DEALLOCATE log_curs
---------------------------------------------------

8) Once again Exec sp_change_users_login 'Report' in the restored user db to find the  orphan users. Make sure there are no orphan users.

Method 3 (Transer logins & Passwords between two SQLServer 2005 Versions)

1) Take the script(sp_help_revlogin) from the below link

http://support.microsoft.com/kb/314546/

Modify some lines as shown in below only if you are moving/migrating only selected database(s) else go to step2

ie;

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

 
As

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 )
        join Migrating_UserDB..sysusers u on u.sid = l.sid
 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 )
      join Migrating_UserDB..sysusers u on u.sid = l.sid
      WHERE p.type IN ( 'S', 'G', 'U' ) AND p.name = @login_name


Note: Here we are joining the master/sys.syslogins with Migrating_UserDB to get only the logins, users specific to the user database which we are migrating/moving. Make sure to change the necessary changes(as shown below) in the script.

2) Copy the result of the above procedure & save it
3) Move the needed database to destination server by backup/restore or attach/detach
4) Exec sp_change_users_login 'Report' in the restored user db to find the orphan users.
5) Exec the above saved result from step1 in the destination server, in the restored
    user database.
6)  Once again Exec sp_change_users_login 'Report' in the restored user db to find the  orphan users.
7) If any more orphan users are existing run the below script to link the orphan users
    to the newly created logins from the result script of step1

-------------- script to correct login IDs --------
declare @login sysname
declare log_curs cursor for
select name from sysusers where upper(name) 'DBO' and status=2

open log_curs
fetch next from log_curs into @login
WHILE (@@FETCH_STATUS -1)
BEGIN
   IF (@@FETCH_STATUS -2)
   BEGIN  
      exec sp_change_users_login 'Update_One', @login, @login
      Print 'Login Updated: "' + @login + '".'
   END
   FETCH NEXT FROM log_curs INTO @login
END
CLOSE log_curs
DEALLOCATE log_curs
---------------------------------------------------


8) Once again Exec sp_change_users_login 'Report' in the restored user db to find the  orphan users. Make sure there are no orphan users.

Remarks: Review the script output carefully before execution in the destination server. Check the windows domain login accounts if the destination server is in a different domain.

 

Comments (44)
  • OdessaLancaster34  - reply
    People deserve very good life and loans or just commercial loan would make it better. Because freedom depends on money state.
  • custom coursework  - answer
    I opine that everybody knows gcse coursework completing is essential for university students. Moreover, there're a lot of custom writing firms that suggest to order courseworks of the best quality.
  • thomas sabo charms  - thomas sabo charms
    I find it incredible that more blogs and forums are not as pleasant as this one. Often times when I land on a website page the articles and other content is so deficient that I move on without delay. That is not the case here. Thanks so much.
  • essays for sale  - respond this post
    Professionally written academic papers aren't a problem now just because high school students can buy an essay online. Previous years people didn't have got such kinds of advantages.
  • Buy Windows 7
    Brendan xzq Grant,Office 2007 Product Key, a new Microsoft employee,Windows 7 Key, recently wrote about his first month here on his I Hate Linux blog. Check out this excerpt:
    NEO,Windows 7 Professional Activation, it was afterwards I got to join the team officially,Office Professional Plus 2010, meet my new co-workers and begin to learn things behind the scenes details that I would have killed to have known (and blogged about) earlier.
    At the end of my first day with the team there was a team-wide meeting (a weekly thing) and when I finished introducing myself,Office Professional Plus 2007, General Manager Charlie Kindel spoke up and said "For those of you who know the I Hate Linux blog... that's him,Buy Office 2010!"
    Since then it's pretty amazing meeting and working with people who know my work and whose work I know... even though only now am I able to put names to various components and technologies,Office Enterprise 2007, but also names I recognized from the beta test ...
  • ugg outlet  - http://www.timberlandoutletboots.org/
    ugg outlet,ugg boots outlet,uggs outlet,uggs boots outlet,Ugg Outlet,Ugg Bailey Button Boots,Ugg Bailey Button Triplet Boots,Ugg Bailey Button Fancy/Krinkle Boots,Ugg Classic Tall Boots,Ugg Classic Short Boots,Ugg Special Short Boots,Ugg Special Tall Boots,Ugg Classic Argyle Knit Boots,Ugg Classic Cardy Boots,Ugg Classic Metallic Boots,Ugg Classic Mini Boots,Ugg Gissella Boots,Ugg Elsey Boots,Ugg Dakota Moccasin Sandals,Ugg Scuffette Sandals,Ugg Ultra Boots,Ugg Ultimate Boots,Ugg Delaine Boots,Ugg Sundance Boots,Ugg Fringe Cardy Boots,Ugg Sheepskin Cuff Boots,Ugg Jimmy Choo Boots 5829,UGG Jimmy Choo Boots,Ugg Nightfall Boots 5359,Ugg Mayfaire Boots 5116,Ugg Tall Boots 5885,Ugg Half Waterproofing Boots 5918,Ugg Roxy Tall Boots 5818,Ugg 5531 Leather Boots,Ugg Kenly Boots 1890,Ugg Greenfield Boots 1891,Ugg Special Style Boots 5899,Ugg Scarf/Hat,Ugg Gloves,Ugg Amelie Sandals,Ugg Basil Slippers,Ugg Brook Slipper,Ugg Dakota Sandals,Ugg Handbags,Mens Ugg Boots,Mens Ugg Butte Boots,Mens Ugg...
  • uggs sale  - uggs sale
    By all means, they look dangerously comfy,uggs sale, that I wouldn’t be surprised if you caught me accidentally walking down to belstaff jacket. Even so, I am feeling stress-fully torn between my belstaff jackets for comfort and their link to my Grandmother’s ugg canada. Surely, if I pop these on it doesn’t mean I’ve crossed the line between stylish and uggs sale? As long as Countryfile isn’t on that ugg canada.Perhaps it’s just my own irrational fear of picturing these slippers with ugg classic tall? If, however, these luxurious bailey button ugg were teamed with your favourite check pyjama trousers and an oversized t-shirt ugg bailey button, and accessorized with some bailey button uggs then I reckon we’d have an indoor-shoe winner.clw817
  • ugg boots sale  - ugg boots sale
    Located in Canada,we provide you with best quality luxurious ugg boots sale. belstaff jackets are selling all around the globe. Choose from our belstaff jacket,and Lace Up boots as well as our enormously popular uggs canada. Kids and baby boots are also available, as well as slippers and scuffs and our uggs canada range and Desert boots. To complement our ugg boots canada we also offer top quality Pashmina shawls. Don't forget to visit our specials page and grab yourself a ugg classic tall boots!At ugg bailey button you will not only receive the best quality products, but highly competitive prices and excellent customer service. If you can't find what you are looking for or have questions on any of our bailey button uggs, please visit uggs bailey button or contact us for more information.clw824
  • Dell Studio 17 Akku  - Dell Studio 17 Akku
    Wie viel Einfluss haben die OEMs haben? Können Sie sagen, der Dell Inspiron 630M Akku Dell D630 Akku Träger, dass Sie ein Telefon wollen ihren ursprünglichen Namen / Branding (zB Samsung Galaxy S II) zu halten oder wenn Sie nicht mit einem Namen nicht einverstanden sind, können Sie wieder zu forcieren.
  • Dell E1505 Akku  - http://www.dellakku.de/Dell-Inspiron-1300-akku.htm
    zwei der PayPal Dell Studio 17 Akku Mitbegründer in einem Interview hier gepflegt heute auf der TechCrunch Dell E1505 Akku Disrupt Konferenz
  • belstaff jackets
    Belstaff Mens Jakects leads bodies to feel some white, belstaff colonial access accoutrements some cannot aggressiveness the lonely, let the admiration cannot be quiet.Belstaff Jackets has in fact gone aloft all added shoe brands. This casting has in fact artificial the lives of men and women beside and stylish. This casting is acclimatized for its able and connected shoes.
  • moncler men jackets
    The absolute of the Moncler Jackets Men is absolute bendable and mild from the abutting side.You can calmly get Moncler accoutrement to adequate your personality and ambulatory your aftereffect on Moncler KID Jackets.The designs are set up brash for the best attainable affluence and affluence about everywhere in winters alternating with giving a getting which includes a chichi appear and feel.
  • christian louboutin sale  - christian louboutin sales
    Thank you for sharing the wonderful pictures and idea to us. Popular season in 2011, herve leger dress and christian louboutin sale you can find popular with high quality clothes and shoes, we can provide a lot of 2011 new style of the best herve leger dress shoes and the Christian Louboutin clothes. Herve leger replica with excellent quality and as an original copy same design because of its attention and sexy design style, it attracts many international customers, including the world's most beautiful and the most fashionable women, Hollywood movie star. Modern, Christian Louboutin on women standing is preferred. With more and more fine, more and more high, once in the christian louboutin sales, breast will be standing naturally, the arc of the hip will more tight become warped, on the vision to strengthen the feminine qualities, show the convex curve bending before, natural have feminine taste. In 2011, put on herve leger replica dress and christian louboutin high boots, 2010 tro...
  • Anonymous
    Even though Larry Bird and Magic Johnson turned the league from a third-rate carnival in the late 1970s to a main attraction in the 1980s, some have rewritten history to cast Jordan as the ultimate hero. Jordan wasn’t the first to capitalize on endorsements and he didn’t christen the dunk contest, but he may have finally found a way to put his stamp on the game in a way that no one—not Bird, Magic or Julius Erving—has done before: he’s going to try to euthanize an entire season.
    Welcome to pick up your favorite best shoes products on our online store.
    wholesale jordan shoes
    Nike Air Force 1
    chanel sunglasses
    coach boots
    jordan shoes 2011
    louis vuitton shoes
    coach shoes
    Nike Free Run
    Nike Air Max 2011
    Nike Dunk High
    Do you want to have a new feeling of products of enjoyment?Come on please!
  • Christian Louboutin Ankle Boot  - Christian Louboutin Ankle Boots

    Ccx
    It is really nice of you to share the excellent shoes information to others.
    Christian Louboutin Pumps foot that one wipe enthusiastic red, no matter how plain clothes, they were unable to hide the hostess as fire the lively personality. Modern, Christian Louboutin High Boots for women is stand for beautiful. Heel becoming larger and more and more high, once in Christian Louboutin Bags , breast will natural standing, coxal radian will be more tightening become warped, on the vision strengthened the woman idiosyncratic, show lordosis of curved curve, natural after have woman flavour. Christian Louboutin Flats, perhaps no high-heeled shoes enchanting scenery, but designers have mastered the female people's psychology, now designed Christian Louboutin Ankle Boots , lovely and elegant, appropriate safety. When a woman loves Christian Louboutin Evening is really began to enjoy doing a woman's feelings, love Christian Louboutin Sneakers of woman, all louboutin evening shoes not neg...
  • Anonymous
    As opposed to making use of its conventional louis vuitton speedy supplies, this season Louis Vuitton has released a brand new series-the Louis Vuitton Slightly Denim. Just as its name tells, the bag is slight in weight for the light denim it made use of cheap louis vuitton and will cheer you up inside the downturn economy with its easy but sophisticated color.Pretty much for every single woman, besides the outfits, handbags are really a further kind of important accessories in her wardrobes. Nowadays, handbags aren't restricted towards Tiffany and CO the standard function of holding every day essentials. Shopping for a Louis Vuitton monogrammed Vernis purse is an investment within your fashion louis vuitton artsy future. The LV and 4 pointed flower monogram are renowned world-wide Tiffany jewelry outlet. In truth, the Louis Vuitton brand name is one of the most pricey names within the globe, products notwithstanding.One thing that you simply need to normally keep in mind regarding ...
  • Anonymous
    In a nod to Victoriana louis vuitton speedy 25, Zoe Saldana wore a charmingly dishabille design in shades of crimson by Louis Vuitton.One casualty from louis vuitton neverfull the sales slump was UK based supermarket giant, Tesco -- the world's third largest retailer -- which was forced to offer you a profit louis vuitton speedy 35 warning within the wake of a disappointing UK Christmas trading period. It saw a 2.3% fall of like for like louis vuitton artsy GM | PM sales on the previous year.Outside of Asia and Brazil, wealthy buyers are also reaching for their Louis Vuitton purses once again following louis vuitton artsy a number of years of downturn-induced caution, in accordance with louis vuitton luggage.Such figures are in contrast for the bleak atmosphere elsewhere inside the retail sector louis vuitton speedy 30. European Commission figures show that sales fell by 2.5% inside the eurozone amongst November 2010 and 2011, and by 1.3% across the European Union louis vuitton speedy.Inside a split decision, a three-judge panel of the 9th U.S. Circuit Court of Appeals discovered the state's Proposition 8 "works a meaningful harm to gays and lesbians" by denying their right to civil marriage i...
  • loans  - answer
    Specialists state that loan aid a lot of people to live their own way, because they are able to feel free to buy necessary stuff. Moreover, different banks give collateral loan for young and old people.
Write comment
Your Contact Details:
Comment:
[b] [i] [u] [url] [quote] [code] [img]   
:D:angry::angry-red::evil::idea::love::x:no-comments::ooo::pirate::?::(
:sleep::););)):0
Security
Please input the anti-spam code that you can read in the image.
 
Copyright 2009 SQL Server.in, Powered by Joomla!; Joomla templates by SG web hosting