Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_SetAutoSAPasswordAndDisable

  No additional text.


Syntax
create procedure sys.sp_SetAutoSAPasswordAndDisable
as
    -- can execute only as SysAdmin
	if (not (is_srvrolemember('sysadmin') = 1))  -- Make sure that it is the SA executing this.
	begin
		raiserror(15247,-1,-1)
		return(1)
	end

   	-- Begin a transaction
   	BEGIN TRANSACTION
   	
	-- Disable Password Policy on the SA Login
	ALTER LOGIN sa WITH CHECK_POLICY = OFF
	IF @@ERROR <> 0
	BEGIN
		ROLLBACK TRANSACTION
		RETURN (1)
	END

	-- Create a New Guid as the random password
	declare @randompwd UNIQUEIDENTIFIER
	declare @stmt nvarchar(4000)
	SET @randompwd = newid()
	SELECT @stmt = 'ALTER LOGIN sa WITH PASSWORD = ' + quotename(@randompwd, '''')
	EXEC(@stmt)
	IF @@ERROR <> 0
	BEGIN
		ROLLBACK TRANSACTION
		RETURN (1)
	END

	-- Now set the policy back
	ALTER LOGIN sa WITH CHECK_POLICY = ON
	IF @@ERROR <> 0
	BEGIN
		ROLLBACK TRANSACTION
		RETURN (1)
	END	

	-- Now set the policy back
	ALTER LOGIN sa DISABLE
	IF @@ERROR <> 0
	BEGIN
		ROLLBACK TRANSACTION
		RETURN (1)
	END	

	-- Commit the transaction
	COMMIT TRANSACTION

 
Last revision 2008RTM
News

  Query a named instance
Sybase+ASE+silent+install
SQL 2008 R2
Deprecated procedures in SQL2008
Reporting Services item-level role definitions
Create all your missing indexes
Converting datetime field
Start MSSQL Server Profiler at time
Replicating MSSQL Server views
Exploring Microsoft Sharepoint
The OLE DB provider "SQLNCLI10" for linked server indicates.
Mobile solar charger
Oracle to SQL Server replication
Cannot insert the value NULL into column
Undocumented Microsoft SQL Server 2008
VMware
Zoekmachine optimalisatie
SQL Servers hidden objects
FckEditor
Flash in Ajax
De hype die AJAX heet
Barcode scannen
MySQL; Gratis, makkelijk en snel!
PHP
sIFR; de combinatie tussen HTML en Flash