Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change SQL Server authorization mode without Management Studio

Is there a way to change the authorization mode in SQL Server 2008 or 2012 without using the SQL Server Management Studio?

like image 569
rkmax Avatar asked Aug 15 '12 16:08

rkmax


People also ask

How do I change authentication mode in SQL Server?

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.

How do I enable SQL Server and Windows authentication mode?

2.3 Enabling SQL Authentication or Mixed AuthenticationRight-click the server you wish to modify and then click Properties. Select the Security Page. Under the Server authentication heading choose either the desired authentication: Windows Authentication or SQL Server and Windows Authentication mode. Click OK.

What are the two authentication modes in SQL Server?

SQL Server supports two authentication modes, Windows authentication mode and mixed mode. Windows authentication is the default, and is often referred to as integrated security because this SQL Server security model is tightly integrated with Windows.

Where is SQL Server authentication mode?

In SQL Server Management Studio Object Explorer, right-click on the server name, click Properties and go to Security page to check the SQL Server Authentication. In this case we can see that it is Windows Authentication mode.

How do I turn off Windows authentication mode in SQL Server?

In Object Explorer, open Security folder, open Logins folder. Right click on the local account and go to Properties. In the Login Properties window, select the Status tab. Set Login to Disabled, or set Permission to connect to database engine to Deny.


1 Answers

Here is what Management Studio does to change the authentication mode from mixed to Windows only:

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

And from Windows only back to mixed:

EXEC xp_instance_regwrite 
    N'HKEY_LOCAL_MACHINE', 
    N'Software\Microsoft\MSSQLServer\MSSQLServer', 
    N'LoginMode', 
    REG_DWORD, 
    2; -- only difference is right here

You can call the same command from various sources that can connect to SQL Server such as SQLCMD, PowerShell, VBScript, C#, etc. Or you can log directly onto the server, navigate to that registry key, and change the value manually (as @marc_s suggested).

Note that in all cases you have to restart SQL Server in order for the changes to take effect. You can view the first several entries in the new error log on restart to validate that the authentication mode is correct. It will say (for mixed):

date/time    Server    Authentication Mode is MIXED.
like image 150
Aaron Bertrand Avatar answered Oct 13 '22 07:10

Aaron Bertrand