2

How I can give the sys_admin rights to the local administrator for the SQL Server 2014 database while I installed it using the domain admin account, not local administrator account? Below is the requirement of a manual.

SQL Server installation

During the installation of AlarmInsight components it is required to use local Administrator login. The SQL Server Installation can also be done with local Administrator login by giving required access rights. If another login is used to install SQL Server, the local Administrator has to be given sys_admin rights in the SQL Server Database.

1
  • 1
    login using domain admin account and add a new login for local account.
    – McNets
    Commented Nov 15, 2016 at 19:17

1 Answer 1

2

I had to reread the vendor requirements a couple of times, but I take the instructions to mean the local administrator account only requires elevated permissions during installation. Run one of the following blocks prior to the app install to set this up.

-- Add the Local Administrators Group
USE [master]
GO
CREATE LOGIN [BUILTIN\Administrators] FROM WINDOWS WITH DEFAULT_DATABASE=[master]
GO
ALTER SERVER ROLE [sysadmin] ADD MEMBER [BUILTIN\Administrators]
GO

-- Or Add only the Local Administrator User - Dynamic SQL to capture servername
DECLARE @hostname NVARCHAR(128), @createStmt NVARCHAR(MAX)
SELECT @hostname = CAST(SERVERPROPERTY(N'ComputerNamePhysicalNetBIOS') AS NVARCHAR(128))

SET @createStmt = N'USE [master];' + CHAR(13) + CHAR(10) +
    N'CREATE LOGIN [' + @hostname + N'\Administrator] FROM WINDOWS WITH DEFAULT_DATABASE=[master];' + CHAR(13) + CHAR(10) +
    N'ALTER SERVER ROLE [sysadmin] ADD MEMBER [' + @hostname + N'\Administrator];'

PRINT @createStmt
EXECUTE (@createStmt)
GO

When the installation is complete, be sure to back out these permissions as they are not the most secure, by running one of the following:

-- Drop Local Administrators group
USE [master]
GO
DROP LOGIN [BUILTIN\Administrators]
GO

-- Or Drop the explicitly defined Local Administrator login
DECLARE @hostname NVARCHAR(128), @createStmt NVARCHAR(MAX)
SELECT @hostname = CAST(SERVERPROPERTY(N'ComputerNamePhysicalNetBIOS') AS NVARCHAR(128))

SET @createStmt = N'USE [master];' + CHAR(13) + CHAR(10) +
    N'DROP LOGIN [' + @hostname + N'\Administrator];'

PRINT @createStmt
EXECUTE (@createStmt)
GO

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.