<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>SQL Server 2005: a proposed update of sp_help_revlogin</title><link>http://blogs.msdn.com/lcris/archive/2006/04/03/567680.aspx</link><description>The sp_helprevlogin procedure is described in KB article 246133 . This procedure generates a script that can be used to recreate the logins that exist on a server at a specific point in time. It can be useful for transferring logins from one server to</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: SQL Server 2005: a proposed update of sp_help_revlogin</title><link>http://blogs.msdn.com/lcris/archive/2006/04/03/567680.aspx#567713</link><pubDate>Tue, 04 Apr 2006 02:26:46 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:567713</guid><dc:creator>Eric Newton</dc:creator><description>So why doesnt Sql Server just use logins defined in the databases attached? &lt;BR&gt;&lt;BR&gt;Why is it that Sql Server simply must transfer logins? &amp;nbsp;I can see a point where a particular login needs access to multiple databases. &amp;nbsp;However, more and more this simply isnt the norm... I myself havent used ANY databases that have logins that need "inter-database" access, so why not just have the Server enumerate logins defined at the database level and soft-transfer them into its own auth routine? &lt;BR&gt;&lt;BR&gt;Just seems backwards to me...</description></item><item><title>re: SQL Server 2005: a proposed update of sp_help_revlogin</title><link>http://blogs.msdn.com/lcris/archive/2006/04/03/567680.aspx#567889</link><pubDate>Tue, 04 Apr 2006 07:51:33 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:567889</guid><dc:creator>Sharon Dooley</dc:creator><description>Well, it will create the logins if you use Copy Database Wizard, and it will move all logins or only those used by the databases being copied. &lt;BR&gt;&lt;BR&gt;But there are cases (log shipping, database mirroring) where you need to have the logins the same but are not attaching the database but using restore. A restore to a second server has no access to the login information from the first server; all that's stored in the database is the user name and the login SID. &lt;BR&gt;&lt;BR&gt;So this procedure is extremely useful and necessary. &lt;BR&gt;&lt;BR&gt;Sharon</description></item><item><title>re: SQL Server 2005: a proposed update of sp_help_revlogin</title><link>http://blogs.msdn.com/lcris/archive/2006/04/03/567680.aspx#568277</link><pubDate>Tue, 04 Apr 2006 20:34:48 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:568277</guid><dc:creator>lcris</dc:creator><description>Also, because logins are server level entities, they are not stored at the database level, so they can't be moved with the database, as Eric seems to suggest, if I am understanding his question right.</description></item><item><title>re: SQL Server 2005: a proposed update of sp_help_revlogin</title><link>http://blogs.msdn.com/lcris/archive/2006/04/03/567680.aspx#578313</link><pubDate>Tue, 18 Apr 2006 18:36:32 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:578313</guid><dc:creator>Jon Baker</dc:creator><description>Looks like MSFT updated the KB article with your script, but they are still referencing this as SQL 2000 information. &amp;nbsp;Of course this script does not work with SQL 2000. &amp;nbsp;It might be nice to have a conditional statement to work for both!
&lt;br&gt;
&lt;br&gt;Jon
&lt;br&gt;</description></item><item><title>re: SQL Server 2005: a proposed update of sp_help_revlogin</title><link>http://blogs.msdn.com/lcris/archive/2006/04/03/567680.aspx#578476</link><pubDate>Tue, 18 Apr 2006 22:21:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:578476</guid><dc:creator>lcris</dc:creator><description>Yes, this is an error. The article will be updated. The procedure I posted uses syntax introduced in SQL Server 2005, so it is not possible to write a common version that will work on both SQL Server 2000 and SQL Server 2005. You will need to use a 2000 version when working on 2000 servers and a 2005 version when working with 2005 servers.
&lt;br&gt;</description></item><item><title>re: SQL Server 2005: a proposed update of sp_help_revlogin</title><link>http://blogs.msdn.com/lcris/archive/2006/04/03/567680.aspx#579290</link><pubDate>Wed, 19 Apr 2006 22:58:23 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:579290</guid><dc:creator>edwardp</dc:creator><description>You could easily have both scripts in one wrapper with a quick check to the version ran against and a goto to send to the right block of code to run. I have modified the sql2000 version to also insert the default database for both win and sql logins it came of the original server with.
&lt;br&gt;
&lt;br&gt;sqlscripters@hotmail.com
&lt;br&gt;
&lt;br&gt;Enjoy:
&lt;br&gt;
&lt;br&gt;CREATE PROCEDURE sp_help_revlogin_Mod @login_name sysname = NULL 
&lt;br&gt;AS &amp;nbsp;
&lt;br&gt;--Microsoft Corporation / Public Web Content 
&lt;br&gt;---sp_help_revlogin Modified by edwardp 12/5/2003 to return and print
&lt;br&gt;-- the default database for each login as it generates the script
&lt;br&gt;									
&lt;br&gt;DECLARE @name &amp;nbsp; &amp;nbsp;sysname
&lt;br&gt;DECLARE @xstatus int
&lt;br&gt;DECLARE @binpwd &amp;nbsp;varbinary (255)
&lt;br&gt;DECLARE @txtpwd &amp;nbsp;sysname
&lt;br&gt;DECLARE @tmpstr &amp;nbsp;varchar (255)
&lt;br&gt;DECLARE @tmpstr2 varchar (255)
&lt;br&gt;DECLARE @dbnm varchar (255)
&lt;br&gt;DECLARE @dbnm2 varchar (255)
&lt;br&gt;
&lt;br&gt;IF (@login_name IS NULL)
&lt;br&gt;--We needed to pull the dbid from the sys table
&lt;br&gt; &amp;nbsp;DECLARE login_curs CURSOR FOR 
&lt;br&gt; &amp;nbsp; &amp;nbsp;SELECT name, xstatus, password, dbid FROM master..sysxlogins 
&lt;br&gt; &amp;nbsp; &amp;nbsp;WHERE srvid IS NULL AND name &amp;lt;&amp;gt; 'sa'
&lt;br&gt;ELSE
&lt;br&gt; &amp;nbsp;DECLARE login_curs CURSOR FOR 
&lt;br&gt; &amp;nbsp; &amp;nbsp;SELECT name, xstatus, password, dbid FROM master..sysxlogins 
&lt;br&gt; &amp;nbsp; &amp;nbsp;WHERE srvid IS NULL AND name = @login_name
&lt;br&gt;
&lt;br&gt;OPEN login_curs 
&lt;br&gt;FETCH NEXT FROM login_curs INTO @name, @xstatus, @binpwd, @dbnm
&lt;br&gt;
&lt;br&gt;IF (@@fetch_status = -1)
&lt;br&gt;
&lt;br&gt;BEGIN
&lt;br&gt; &amp;nbsp;PRINT 'No login(s) found.'
&lt;br&gt; &amp;nbsp;CLOSE login_curs 
&lt;br&gt; &amp;nbsp;DEALLOCATE login_curs 
&lt;br&gt; &amp;nbsp;RETURN -1
&lt;br&gt;END
&lt;br&gt;
&lt;br&gt;SET @tmpstr = '/* sp_help_revlogin_Mod script ' 
&lt;br&gt;PRINT @tmpstr
&lt;br&gt;SET @tmpstr = '** Generated ' 
&lt;br&gt; &amp;nbsp;+ CONVERT (varchar, GETDATE()) + ' on ' + @@SERVERNAME + ' */'
&lt;br&gt;PRINT @tmpstr
&lt;br&gt;PRINT ''
&lt;br&gt;PRINT 'DECLARE @pwd sysname'
&lt;br&gt;WHILE (@@fetch_status &amp;lt;&amp;gt; -1)
&lt;br&gt;BEGIN
&lt;br&gt; &amp;nbsp;IF (@@fetch_status &amp;lt;&amp;gt; -2)
&lt;br&gt; &amp;nbsp;BEGIN
&lt;br&gt; &amp;nbsp; &amp;nbsp;PRINT ''
&lt;br&gt; &amp;nbsp; &amp;nbsp;SET @tmpstr = '-- Login: ' + @name
&lt;br&gt; &amp;nbsp; &amp;nbsp;PRINT @tmpstr
&lt;br&gt;
&lt;br&gt;--We use a function to convert the db_id to the DB_NAME since
&lt;br&gt;--the sp's do not accept the db id as an argument
&lt;br&gt;--We only want valid logins so at the NT login has access is where we apply the fix
&lt;br&gt; 
&lt;br&gt;	Select @dbnm2 = DB_NAME(@dbnm)
&lt;br&gt; &amp;nbsp; &amp;nbsp;IF (@xstatus &amp;amp; 4) = 4
&lt;br&gt; &amp;nbsp; &amp;nbsp;BEGIN -- NT authenticated account/group
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;IF (@xstatus &amp;amp; 1) = 1
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;BEGIN -- NT login is denied access
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SET @tmpstr = 'EXEC master..sp_denylogin ''' + @name + ''''
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;PRINT @tmpstr 
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;END
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;ELSE BEGIN -- NT login has access
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SET @tmpstr = 'EXEC master..sp_grantlogin ''' + @name + '''' &amp;nbsp;
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;PRINT @tmpstr
&lt;br&gt;	SET @tmpstr2 = 'EXEC master..sp_defaultdb ''' + @name + '''' + ',' + ' ' + '''' + @dbnm2 + ''''
&lt;br&gt;	Print '-- Needed to Set Default Db Seperately from the login with a windows login'
&lt;br&gt;	PRINT @tmpstr2
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;END
&lt;br&gt; &amp;nbsp; &amp;nbsp;END
&lt;br&gt; &amp;nbsp; &amp;nbsp;ELSE BEGIN -- SQL Server authentication
&lt;br&gt;--SQL logins both null passwords and valid are fixed here
&lt;br&gt;
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;IF (@binpwd IS NOT NULL)
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;BEGIN -- Non-null password
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;EXEC sp_hexadecimal @binpwd, @txtpwd OUT
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;IF (@xstatus &amp;amp; 2048) = 2048
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SET @tmpstr = 'SET @pwd = CONVERT (varchar, ' + @txtpwd + ')'
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ELSE
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SET @tmpstr = 'SET @pwd = CONVERT (varbinary, ' + @txtpwd + ')'
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;PRINT @tmpstr 
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SET @tmpstr = 'EXEC master..sp_addlogin ''' + @name 
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;+ ''', @pwd ' + ',' + ' ' + '''' + @dbnm2 + ''''+','+' @encryptopt = '
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;END
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;ELSE BEGIN 
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;-- Null password
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SET @tmpstr = 'EXEC master..sp_addlogin ''' + @name 
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;+ ''', NULL' + ',' + ' ' + '''' + @dbnm2 + ''''+','+' @encryptopt = '
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;END
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;IF (@xstatus &amp;amp; 2048) = 2048
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;-- login upgraded from 6.5
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SET @tmpstr = @tmpstr + '''skip_encryption_old''' 
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;ELSE 
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SET @tmpstr = @tmpstr + '''skip_encryption'''
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;PRINT @tmpstr 
&lt;br&gt; &amp;nbsp; &amp;nbsp;END
&lt;br&gt; &amp;nbsp;END
&lt;br&gt; &amp;nbsp;FETCH NEXT FROM login_curs INTO @name, @xstatus, @binpwd, @dbnm
&lt;br&gt; &amp;nbsp;END
&lt;br&gt;CLOSE login_curs 
&lt;br&gt;DEALLOCATE login_curs 
&lt;br&gt;RETURN 0
&lt;br&gt;
&lt;br&gt;GO</description></item><item><title>re: SQL Server 2005: a proposed update of sp_help_revlogin</title><link>http://blogs.msdn.com/lcris/archive/2006/04/03/567680.aspx#579435</link><pubDate>Thu, 20 Apr 2006 02:11:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:579435</guid><dc:creator>lcris</dc:creator><description>You're right, I stand corrected: it is possible to combine both implementations as long as the use of new syntax is restricted to dynamic SQL. If you want to do this with the implementation I posted, you would need to rewrite the use of the loginproperty builtin, because the current use would not allow you to create the procedure in SQL Server 2000.
&lt;br&gt;</description></item><item><title>re: SQL Server 2005: a proposed update of sp_help_revlogin</title><link>http://blogs.msdn.com/lcris/archive/2006/04/03/567680.aspx#579840</link><pubDate>Thu, 20 Apr 2006 16:23:12 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:579840</guid><dc:creator>edwardp</dc:creator><description>Ah, seems we are both right. </description></item><item><title>re: SQL Server 2005: a proposed update of sp_help_revlogin</title><link>http://blogs.msdn.com/lcris/archive/2006/04/03/567680.aspx#585454</link><pubDate>Fri, 28 Apr 2006 00:10:56 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:585454</guid><dc:creator>Home Brew</dc:creator><description>Is there a way to script the database permissions for each login ?</description></item><item><title>re: SQL Server 2005: a proposed update of sp_help_revlogin</title><link>http://blogs.msdn.com/lcris/archive/2006/04/03/567680.aspx#585491</link><pubDate>Fri, 28 Apr 2006 01:13:49 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:585491</guid><dc:creator>lcris</dc:creator><description>You can extract the permissions from the sys.server_permissions catalog, but I don't know of a procedure or tool that already does this.
&lt;br&gt;
&lt;br&gt;Ideally, the database administrator should maintain such a script to record all permission operations.
&lt;br&gt;</description></item><item><title>re: SQL Server 2005: a proposed update of sp_help_revlogin</title><link>http://blogs.msdn.com/lcris/archive/2006/04/03/567680.aspx#590158</link><pubDate>Thu, 04 May 2006 22:52:43 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:590158</guid><dc:creator>SQLgiant</dc:creator><description>Thanks for providing an answer regarding the Error in KB article 246133 that still references the sp_help_rev_Login version as a SQL2000 script, which it clearly is not. &lt;BR&gt;&lt;BR&gt;A link in the article to the old SQL2000 script would be a decent fix, and a comment in the script itselt would be useful. For some time, many will need both versions, as I do now. Guess I will go fishing on my old servers...</description></item><item><title>re: SQL Server 2005: a proposed update of sp_help_revlogin</title><link>http://blogs.msdn.com/lcris/archive/2006/04/03/567680.aspx#733653</link><pubDate>Thu, 31 Aug 2006 18:57:46 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:733653</guid><dc:creator>edwardp</dc:creator><description>I use this as a stand alone type script now not a proc since I pull it into a VB Script that parses a txt with server names which it then goes to each building 
&lt;br&gt;the revlogin script 1 per server. I confirmed this works for SQL7 also but not SQL2005 which I think a new one would be better to capture some of the new 
&lt;br&gt;password options. To use as a standalone remove create, Declare the login_name variable and comment out the Returns.
&lt;br&gt;
&lt;br&gt;COPY BELOW HERE:
&lt;br&gt;
&lt;br&gt;--if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_help_revlogin2k_Mod]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
&lt;br&gt;--drop procedure [dbo].[sp_help_revlogin2k_Mod]
&lt;br&gt;GO
&lt;br&gt;
&lt;br&gt;SET QUOTED_IDENTIFIER OFF 
&lt;br&gt;GO
&lt;br&gt;SET ANSI_NULLS ON 
&lt;br&gt;GO
&lt;br&gt;
&lt;br&gt;CREATE PROCEDURE sp_help_revlogin2k_Mod @login_name sysname = NULL AS
&lt;br&gt;DECLARE @name &amp;nbsp; &amp;nbsp;sysname
&lt;br&gt;DECLARE @xstatus int
&lt;br&gt;DECLARE @binpwd &amp;nbsp;varbinary (256)
&lt;br&gt;DECLARE @txtpwd &amp;nbsp;sysname
&lt;br&gt;DECLARE @tmpstr &amp;nbsp;varchar (256)
&lt;br&gt;DECLARE @tmpstr2 varchar (255)
&lt;br&gt;DECLARE @dbnm varchar (255)
&lt;br&gt;DECLARE @dbnm2 varchar (255)
&lt;br&gt;DECLARE @SID_varbinary varbinary(85)
&lt;br&gt;DECLARE @SID_string varchar(256)
&lt;br&gt;
&lt;br&gt;IF (@login_name IS NULL)
&lt;br&gt; &amp;nbsp;DECLARE login_curs CURSOR FOR 
&lt;br&gt; &amp;nbsp; &amp;nbsp;SELECT sid, name, xstatus, password, dbid FROM master..sysxlogins 
&lt;br&gt; &amp;nbsp; &amp;nbsp;WHERE srvid IS NULL AND name &amp;lt;&amp;gt; 'sa'
&lt;br&gt;ELSE
&lt;br&gt; &amp;nbsp;DECLARE login_curs CURSOR FOR 
&lt;br&gt; &amp;nbsp; &amp;nbsp;SELECT sid, name, xstatus, password, dbid FROM master..sysxlogins 
&lt;br&gt; &amp;nbsp; &amp;nbsp;WHERE srvid IS NULL AND name = @login_name
&lt;br&gt;OPEN login_curs 
&lt;br&gt;FETCH NEXT FROM login_curs INTO @SID_varbinary, @name, @xstatus, @binpwd, @dbnm
&lt;br&gt;IF (@@fetch_status = -1)
&lt;br&gt;BEGIN
&lt;br&gt; &amp;nbsp;PRINT 'No login(s) found.'
&lt;br&gt; &amp;nbsp;CLOSE login_curs 
&lt;br&gt; &amp;nbsp;DEALLOCATE login_curs 
&lt;br&gt; &amp;nbsp;RETURN -1
&lt;br&gt;END
&lt;br&gt;SET @tmpstr = '/* sp_help_revlogin script ' 
&lt;br&gt;PRINT @tmpstr
&lt;br&gt;SET @tmpstr = '** Generated ' 
&lt;br&gt; &amp;nbsp;+ CONVERT (varchar, GETDATE()) + ' on ' + @@SERVERNAME + ' */'
&lt;br&gt;PRINT @tmpstr
&lt;br&gt;PRINT ''
&lt;br&gt;PRINT 'DECLARE @pwd sysname'
&lt;br&gt;WHILE (@@fetch_status &amp;lt;&amp;gt; -1)
&lt;br&gt;BEGIN
&lt;br&gt; &amp;nbsp;IF (@@fetch_status &amp;lt;&amp;gt; -2)
&lt;br&gt; &amp;nbsp;BEGIN
&lt;br&gt; &amp;nbsp; &amp;nbsp;PRINT ''
&lt;br&gt; &amp;nbsp; &amp;nbsp;SET @tmpstr = '-- Login: ' + @name
&lt;br&gt; &amp;nbsp; &amp;nbsp;PRINT @tmpstr
&lt;br&gt; --We use a function to convert the db_id to the DB_NAME since
&lt;br&gt;--the sp's do not accept the db id as an argument
&lt;br&gt;--We only want valid logins so at the NT login has access is where we apply the fix
&lt;br&gt;Select @dbnm2 = DB_NAME(@dbnm)
&lt;br&gt; &amp;nbsp; &amp;nbsp;IF (@xstatus &amp;amp; 4) = 4
&lt;br&gt; &amp;nbsp; &amp;nbsp;BEGIN -- NT authenticated account/group
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;IF (@xstatus &amp;amp; 1) = 1
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;BEGIN -- NT login is denied access
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SET @tmpstr = 'EXEC master..sp_denylogin ''' + @name + ''''
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;PRINT @tmpstr 
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;END
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;ELSE BEGIN -- NT login has access
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SET @tmpstr = 'EXEC master..sp_grantlogin ''' + @name + ''''
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;PRINT @tmpstr 
&lt;br&gt;	SET @tmpstr2 = 'EXEC master..sp_defaultdb ''' + @name + '''' + ',' + ' ' + '''' + @dbnm2 + ''''
&lt;br&gt;	Print '-- Needed to Set Default Db Seperately from the login with a windows login'
&lt;br&gt;	PRINT @tmpstr2
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;END
&lt;br&gt; &amp;nbsp; &amp;nbsp;END
&lt;br&gt; &amp;nbsp; &amp;nbsp;ELSE BEGIN -- SQL Server authentication
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;IF (@binpwd IS NOT NULL)
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;BEGIN -- Non-null password
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;EXEC sp_hexadecimal @binpwd, @txtpwd OUT
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;IF (@xstatus &amp;amp; 2048) = 2048
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SET @tmpstr = 'SET @pwd = CONVERT (varchar(256), ' + @txtpwd + ')'
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ELSE
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SET @tmpstr = 'SET @pwd = CONVERT (varbinary(256), ' + @txtpwd + ')'
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;PRINT @tmpstr
&lt;br&gt;	EXEC sp_hexadecimal @SID_varbinary,@SID_string OUT
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SET @tmpstr = 'EXEC master..sp_addlogin ''' + @name 
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;+ ''', @pwd' + ',' + ' ' + '''' + @dbnm2 + ''''+','+' @sid = ' + @SID_string + ', @encryptopt = '
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;END
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;ELSE BEGIN 
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;-- Null password
&lt;br&gt;	EXEC sp_hexadecimal @SID_varbinary,@SID_string OUT
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SET @tmpstr = 'EXEC master..sp_addlogin ''' + @name 
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;+ ''', NULL' + ',' + ' ' + '''' + @dbnm2 + ''''+','+' @sid = ' + @SID_string + ', @encryptopt = '
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;END
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;IF (@xstatus &amp;amp; 2048) = 2048
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;-- login upgraded from 6.5
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SET @tmpstr = @tmpstr + '''skip_encryption_old''' 
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;ELSE 
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SET @tmpstr = @tmpstr + '''skip_encryption'''
&lt;br&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;PRINT @tmpstr 
&lt;br&gt; &amp;nbsp; &amp;nbsp;END
&lt;br&gt; &amp;nbsp;END
&lt;br&gt; &amp;nbsp;FETCH NEXT FROM login_curs INTO @SID_varbinary, @name, @xstatus, @binpwd, @dbnm
&lt;br&gt; &amp;nbsp;END
&lt;br&gt;CLOSE login_curs 
&lt;br&gt;DEALLOCATE login_curs 
&lt;br&gt;RETURN 0
&lt;br&gt;GO
&lt;br&gt; ----- End Script -----
&lt;br&gt;
&lt;br&gt;</description></item></channel></rss>