Monthly Archives: December 2011

Migrating SQL Server Database Logins with sp_help_revlogin

You’ve migrated your database to a new box, with no problems.  You created the login that goes with this database, and all is right in the world.  However, when your user goes to connect to it they get the dreaded error 18456, login failed.  But wait, I created the login, right?

Not so fast there, accidental DBA.  You are going to need the help of a nifty stored procedure called sp_help_revlogin.  This stored procedure, provided by Microsoft in the link below, will generate a T-SQL script that will copy the logins, their passwords and their corresponding SIDs (or security identification number, which is usually the culprit here).  This is also a great utility when the database has numerous users with various security levels and passwords.  Really now, who wants to write all of that down and recreate it?  Even with screenshots, it can turn into a large, fat-fingering and time consuming event.  Mind-numbing, I would say.  Why do something manually when you can do it automagically?   Just think of all those happy logins that will not be orphaned by the dark side?

How to transfer the logins and the passwords between instances of SQL Server 2005 and SQL Server 2008.

Here is also a code snippet to check for orphaned logins, for your enjoyment.  Enjoy!

USE <database_name>;
GO
sp_change_users_login @Action='Report';
GO

Merry Christmas Everyone!

I would like to personally wish you and your family a safe and Merry Christmas and a Happy New Year.  I hope 2012 is especially productive and that we all have a very #SQLAwesomeness year!  I look forward to seeing you all at various SQL events in the new year!  I would also like to thank everyone in the SQL Community for everything you do throughout the year to help spread the SQL love, it is appreciated!  Finally, let the Big Gator Growl!

Moving the Master Database Lesson Learned

 With the new 2008R2 servers that were recently built, I am hoping to institute some standard best practices on the boxes moving forward.  The first one was to move the TempDB to its own drive on a separate LUN and since I have moved a TempDB before, no problems here.  The second best practice was to make a separate drive on a separate LUN for the databases and log files, check and check.  The third practice was to move the system databases, which sounded simple in theory but I have never done it before, uncheck–it did not work.

I followed Microsoft’s directions but it did not cover my contingency.  The following excerpt is taken from Microsoft’s MSDN site for SQL Server 2008 R2 in order to Move the Master Database, with changes for my separate drives.  

To move the master database, follow these steps.

  1. From the Start menu, point to All Programs, point to Microsoft SQL Server, point to Configuration Tools, and then click SQL Server Configuration Manager.
  2. In the SQL Server Services node, right-click the instance of SQL Server (for example, SQL Server (MSSQLSERVER)) and choose Properties.
  3. In the SQL Server (instance_name) Properties dialog box, click the Advanced tab.
  4. Edit the Startup Parameters values to point to the planned location for the master database data and log files, and click OK. Moving the error log file is optional.The parameter value for the data file must follow the -d parameter and the value for the log file must follow the -l parameter. The following example shows the parameter values for the default location of the master data and log files.
    -J:\SQL\master.mdf;-eC:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\
    LOG\ERRORLOG;-lJ:\SQL\mastlog.ldf
  5. Stop the instance of SQL Server by right-clicking the instance name and choosing Stop.
  6. Move the master.mdf and mastlog.ldf files to the new location.
  7. Restart the instance of SQL Server. Here is where I had my issue, it would not restart.  Through my troubleshooting I realized that the new folder did not have the same permissions as the original folder.   I added the SQLServerMSSQLUser$<machine name>$<instance name> user that was created by the SQL installer.  Problem solved.
  8. Verify the file change for the master database by running the following query.
     
    SELECT name, physical_name AS CurrentLocation, state_desc
    FROM sys.master_files
    WHERE database_id = DB_ID(‘master’);
    GO
 

MasterDB Results of New Location

Verify the file change

MasterDB Properties

Enjoy!  I hope this helps!