SQL

From WikiWiki
Revision as of 23:49, 21 August 2020 by Mendel (talk | contribs)
(change visibility) (diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Find SQL servers with powershell

[System.Data.Sql.SqlDataSourceEnumerator]::Instance.GetDataSources()

browser agent must be running


getting access to

Add .\administrators to sql administrators

sqlcmd -Q "if not exists(select * from sys.server_principals where name='BUILTIN\administrators') CREATE LOGIN [BUILTIN\administrators] FROM WINDOWS;EXEC master..sp_addsrvrolemember @loginame = N'BUILTIN\administrators', @rolename = N'sysadmin'" –S ComputerName\InstanceName

or run in single user mode

sqlservr -m

or run management studio as system using psexec

PsExec -s -i "C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\Ssms.exe"