Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-06-19 : 11:04:43
|
[code]CREATE PROCEDURE dbo.uspSetSQLServerAuthenticationMode( @MixedMode BIT)ASSET NOCOUNT ONDECLARE @InstanceName NVARCHAR(1000), @Key NVARCHAR(4000), @NewLoginMode INT, @OldLoginMode INTEXEC master..xp_regread N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\Microsoft SQL Server\Instance Names\SQL\', N'MSSQLSERVER', @InstanceName OUTPUTIF @@ERROR <> 0 OR @InstanceName IS NULL BEGIN RAISERROR('Could not read SQL Server instance name.', 18, 1) RETURN -100 ENDSET @Key = N'Software\Microsoft\Microsoft SQL Server\' + @InstanceName + N'\MSSQLServer\'EXEC master..xp_regread N'HKEY_LOCAL_MACHINE', @Key, N'LoginMode', @OldLoginMode OUTPUTIF @@ERROR <> 0 BEGIN RAISERROR('Could not read login mode for SQL Server instance %s.', 18, 1, @InstanceName) RETURN -110 ENDIF @MixedMode IS NULL BEGIN RAISERROR('No change to authentication mode was made. Login mode is %d.', 10, 1, @OldLoginMode) RETURN -120 ENDIF @MixedMode = 1 SET @NewLoginMode = 2ELSE SET @NewLoginMode = 1EXEC master..xp_regwrite N'HKEY_LOCAL_MACHINE', @Key, N'LoginMode', 'REG_DWORD', @NewLoginModeIF @@ERROR <> 0 BEGIN RAISERROR('Could not write login mode %d for SQL Server instance %s. Login mode is %d', 18, 1, @NewLoginMode, @InstanceName, @OldLoginMode) RETURN -130 ENDRAISERROR('Login mode is now %d for SQL Server instance %s. Login mode was %d before.', 10, 1, @NewLoginMode, @InstanceName, @OldLoginMode)RETURN 0[/code] E 12°55'05.25"N 56°04'39.16" |
|
|
|
|
|
|