Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (6.1k points)
How can I change the SQL server authentication mode by just a script?

I want a script which I can execute in the query window and change the authentication to the mixed-mode using it.

How can I do it?

1 Answer

0 votes
by (12.7k points)
edited by

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 the mixed-mode authentication.

You will need to restart SQL Server after changing this setting. You can not able to do that from T-SQL. Using the command prompt(cmd), it is something like net stop mssqlserver then net start mssqlserver.

Want to become an expert in SQL? Join the SQL course fast!

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jan 5, 2021 in SQL by Appu (6.1k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...