How to change SQL Server authorization mode without Management Studio

眉间皱痕 提交于 2019-12-21 12:37:33

问题


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


回答1:


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.



回答2:


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.



来源:https://stackoverflow.com/questions/11972876/how-to-change-sql-server-authorization-mode-without-management-studio

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