How to change SQL Server authorization mode without Management Studio

坚强是说给别人听的谎言 提交于 2019-12-04 06:15:59

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.

I found out that if you installed your SQL express 32bit (in my case) on 64bit Windows, the reg path has to be HKEY_LOCAL_MACHINE\ SOFTWARE\Wow6432Node\Microsoft\MSSQLServer\MSSQLServer. the change here is the Wow6432Node key.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!