Transact-SQL Reference

sp_grantlogin

Allows a Microsoft® Windows NT® user or group account to connect to Microsoft SQL Server™ using Windows Authentication.

Syntax

sp_grantlogin [@loginame =] 'login'

Arguments

[@loginame =] 'login'

Is the name of the Windows NT user or group to be added. The Windows NT user or group must be qualified with a Windows NT domain name in the form Domain\User, for example London\Joeb. login is sysname, with no default.

Return Code Values

0 (success) or 1 (failure)

Remarks

Use sp_grantlogin to reverse the effects of a previous sp_denylogin that has been executed for a Windows NT user.

Use sp_addlogin to allow a SQL Server login to connect to SQL Server.

Although a login can connect to SQL Server after sp_grantlogin has been executed, access to user databases is denied until a user account for the login is created in each database that the login must access. Use sp_grantdbaccess to create a user account in each user database.

sp_grantlogin cannot be executed within a user-defined transaction.

Permissions

Only members of the sysadmin or securityadmin fixed server roles can execute sp_grantlogin.

Examples

This example allows the Windows NT user Corporate\BobJ to connect to SQL Server.

EXEC sp_grantlogin 'Corporate\BobJ'

Or

EXEC sp_grantlogin [Corporate\BobJ]

See Also

sp_addlogin

sp_revokelogin

sp_denylogin

System Stored Procedures