HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlModerate

SQL Server - Is my database being queried over linked server?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
sqlbeingdatabasequeriedserverlinkedover

Problem

Is there a way to know if a specific database on my SQL Server instance is being queried over linked server?

Solution

There is one possible way, it is to look at sessions/connections, and guess by session's properties that this session is coming from unusual source:

select * from sys.dm_exec_sessions s
    join sys.dm_exec_connections c on 
    s.session_id = c.session_id


  • host_name = this is server name, you can find out if there's a SQL Server installed on it



  • client_interface_name = 'OLEDB'



  • program_name = 'Microsoft SQL Server'



  • client_net_address = this is IP address, will hint you to a server which might have SQL Server installed



Especially when you know very well, from which IP addresses and hosts usual connections / sessions (your apps or users) are coming from, you will be able to distinct anything that is suspicious

Then join the sys.dm_exec_requests and sys.dm_exec_sql_text to get the query that session is executing. The query can be like

SELECT ... FROM "DB"."dbo"."Table" "Tbl1002"


This will hint you to a database.

Again, I am not saying this will help in 100% cases, but might help you to identify what you are looking for

Code Snippets

select * from sys.dm_exec_sessions s
    join sys.dm_exec_connections c on 
    s.session_id = c.session_id
SELECT ... FROM "DB"."dbo"."Table" "Tbl1002"

Context

StackExchange Database Administrators Q#302193, answer score: 10

Revisions (0)

No revisions yet.