Andreas Wolter
  • Consulting & Services
    • SQL Server Security Assessment by Andreas Wolter
    • SQL Server Health Check
    • Performance Analysis
    • SQL Server Discovery
    • Air-Gapped SQL Server
  • My Customers
  • About
    • Conferences
    • Certifications
    • Training
  • Blog
  • Contact
  • Click to open the search input field Click to open the search input field Search
  • Menu Menu

DENY CONNECT vs. DISABLE LOGIN in SQL Server: Effect on Impersonation and Permissions

DENY CONNECT vs. DISABLE LOGIN in SQL Server: Effect on Impersonation and Permissions

In short: disabling a login or denying CONNECT blocks direct logon, but not impersonation, and the account keeps all its other permissions.

Action Direct logon Can it still be impersonated (EXECUTE AS)? Its other permissions
ALTER LOGIN … DISABLE (tested on sa and a new login) blocked yes unchanged
DENY CONNECT SQL to a login blocked yes unchanged
DENY CONNECT on a database user (user without login) no access to the database no, EXECUTE AS fails (Msg 916) unchanged

The behavior described here still applies to current SQL Server versions.

A short article on the effects – or missing effects – regarding the disabling & denying connect of Logins & Users on impersonation and permission.

Every once in a while one can observe that Logins or Users have been denied the Connect permission or a Login has been disabled.

Therefore a correct expectation and understanding can be critical.

Test setup

So let’s see a simple demo: We will use the built-in sa-Account, which is used by many as database owner among other (more on that soon in another article – meanwhile I do invite you to still send in data for the survey on that topic), another freshly created Account DeniedLogin and a database called ImpersonateLogin with the according User + another User without Login: SQLUser.

So I am disabling the sa-account as well as the “DeniedLogin”-Account – the latter I also Deny the Connect permission (Remember we “Cannot grant, deny, or revoke permissions to sa, dbo, entity owner, information_schema, sys, or yourself.”)

The Database-User “SQLUser” gets denied the Connect permission on the database.

In the GUI the result looks like this:

Now let’s run 4 tests.

So essentially what those queries do, is trying to impersonate the respective Login or User – and proofing success by returning the then respective active role-memberships.

Results: disabled and denied logins

Results:

DeniedLogin: Impersonation works + No loss of permissions.

In other words: Denying Connect to a Login does not disallow Impersonation. Impersonation is actually another permission which one can use and is not affected even by Disabling the Login!

Same applies for sa: Impersonation works + No loss of permissions.

Results: database user denied CONNECT

In the following test for the User which has been denied the Connect-permission onto the database – and cannot be used as a Login.

Results:

Msg 15517, Level 16, State 1, Line 3

Cannot execute as the database principal because the principal “DeniedLogin” does not exist, this type of principal cannot be impersonated, or you do not have permission.

 

Msg 916, Level 14, State 1, Line 3

The server principal “S-1-9-3-4049223906-1289824279-1154161590-488313048.” is not able to access the database “ImpersonateLogin” under the current security context.


The GUID does not represent a real server-principal, because the User SQLUser does not have a matching Login. So it tells us, that the users cannot be impersonated inside the database.

The difference for the second user is, that this user only exists inside the database but at the same time has been explicitly denied to connect to it. This has essentially the same result as “disabling” it – just as the guest-user is.

Conclusion

Thereby it is shown that disabling of Logins does not give any security against attacks from inside. And so-called privilege elevation (/-escalation) usually takes part from internal.

Also the old “trick”, to drop the default-database of a Login, is of little help.

For database-users is indeed does have an effect and prevents logon/connect to the respective database – also “from inside”.

Consequentially all permissions (besides the one denied of course) of the respective Login and User stay totally unaffected by and method of deactivation.

This is also true in the context of “external access”-permission for Logins based on asymmetric keys. (Here a forum-thread where the question appeared: “SQL Login “disabled” flag does not work with asymmetric key??”)

ALTER LOGIN is also explained in BOL here: technet.microsoft.com/en-us/library/ms189828.aspx

I hope those things clarified some things and especially recommendations in security-matters.


Happy securing


Andreas

Frequently asked questions

Does DENY CONNECT stop impersonation?

Not for logins. A login that is disabled or denied CONNECT SQL can still be impersonated with EXECUTE AS LOGIN, and it keeps all its other permissions. For a database user, DENY CONNECT on the database does block EXECUTE AS USER in that database.

DISABLE vs DENY: which should I use?

Both stop direct logon, and neither protects against impersonation from inside the server. What matters is who holds IMPERSONATE on the login (including through CONTROL SERVER), and which permissions the account still has.

Tags: Privilege Escalation

Categories: Security

A disabled login is not always without access. A security assessment checks the effective permissions on your SQL Servers, including access through impersonation.

Get a SQL Server Security Assessment
Share
  • Share on Facebook
  • Share on X
  • Share on LinkedIn
0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Security Assessment Community Edition

Learn about my free Community Edition script.

Recent
  • Sample result in SSMS: local NTLM connections over shared memory from SQL01, and NTLM connections over TCP from a reporting server, an ETL server and a workstation
    NTLM Deprecation and SQL Server: How to Find NTLM Connections...18. November 2026 - 17:01in: Security
  • SQL Server Consolidation: $3M+ in Projected Savings and...30. September 2026 - 15:47in: Architecture & High Availability, Security
  • Using a Database Server as a Honeypot for Threat Detect...18. September 2026 - 16:00in: Security
  • Azure Arc for SQL Server: “Least Privilege” Mode Still...8. September 2026 - 15:56in: Security
  • When SIEM Enrichment Becomes False Attribution3. September 2026 - 14:26in: Security
Comments
  • Thanks Scott. Goof feedback. NETSTAT is a useful addition,...21. November 2026 - 15:44 by Andreas Wolter
  • I would go a little deeper with how to troubleshoot SQL...21. November 2026 - 15:15 by Scott O
  • Protecting database data at rest is essential for maintaining...21. October 2026 - 2:23 by Viska
  • Thanks Now Microsoft could document them as well, and put...19. August 2026 - 16:26 by Andreas Wolter
  • List of Action_IDs for Filter https://sqlquantumleap.com/reference/server-audit-filter-values-for-action_id/ Great...18. August 2026 - 0:59 by Peter Dünsch

Articles

Analysis Services Auditing Availability Groups Azure Best Practices Certification Columnstore Consolidation Deadlocks & Blocking Encryption Extended Events Get-SqlSafe In-Memory OLTP Indexing Least Privilege PASS Summit Patching Performance Analysis Permissions Privilege Escalation Reporting Services Security Principles Spatial Data SQLBits SQL Injection SQLSaturday SQL Server 2012 SQL Server 2014 SQL Server 2016 SQL Server 2022 SQL Server 2025 SQL Trace & Profiler sysadmin & Server Roles Threat Detection Vulnerabilities Workshop & PreCon
© 2026 Andreas WolterContactImprintPrivacy PolicyLinkedInRSS
Link to: Upcoming Conferences: SQLSaturdays in Denmark and Portugal. Link to: Upcoming Conferences: SQLSaturdays in Denmark and Portugal. Upcoming Conferences: SQLSaturdays in Denmark and Portugal. Link to: Received MVP Award for SQL Server Link to: Received MVP Award for SQL Server Received MVP Award for SQL Server
Scroll to top Scroll to top Scroll to top
Manage Consent
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
  • Manage options
  • Manage services
  • Manage {vendor_count} vendors
  • Read more about these purposes
View preferences
  • {title}
  • {title}
  • {title}