Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change SQL Server authentication mode using script

I am wondering how can someone change the sqlserver authentication mode by just a script?

I need a script to run in query window and change the authentication to mixed mode with it. Any idea?

like image 436
Reza Ameri Avatar asked Sep 22 '12 07:09

Reza Ameri


People also ask

How do I change SQL Server authentication mode?

In SQL Server Management Studio Object Explorer, right-click the server, and then click Properties. On the Security page, under Server authentication, select the new server authentication mode, and then click OK.


1 Answers

For Windows only mode:

EXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE', 
    N'Software\Microsoft\MSSQLServer\MSSQLServer', N'LoginMode', REG_DWORD, 1

Use 2 instead of 1 for mixed authentication.

You'll have to restart SQL Server after changing this setting. You can't do that from T-SQL. From the command prompt, it's something like net stop mssqlserver then net start mssqlserver.

like image 139
Andomar Avatar answered Oct 28 '22 08:10

Andomar