Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting account 'locked' status in SQL Server

I want to unlock one account in SQL Server. Before unlocking I have to check whether that account is locked or not.

I want to unlock only if the account is locked.

Is there any SQL query or stored procedure to get the "Locked" status of SQL user?

like image 671
Santhosha Avatar asked Apr 09 '10 12:04

Santhosha


2 Answers

Posting Answer on Behalf of Alex K.

SELECT LOGINPROPERTY('loginname', 'IsLocked')

like image 70
Santhosha Avatar answered Oct 27 '22 03:10

Santhosha


Do you mean a login name that has Login: Denied ? If so you can:

SELECT is_disabled from sys.server_principals WHERE name = @loginname
like image 33
Alex K. Avatar answered Oct 27 '22 03:10

Alex K.