November 29, 2018 at 12:13 pm
Does anyone have a script to Capture all SQL Connection to table and schedule a job that deletes the entry from the table after 7 days?
November 29, 2018 at 1:03 pm
November 29, 2018 at 2:44 pm
hello_san - Thursday, November 29, 2018 12:13 PMDoes anyone have a script to Capture all SQL Connection to table and schedule a job that deletes the entry from the table after 7 days?
One problem is that connections don't connect to a table. They connect to the server and may be in a particular database but nothing with tables.
Sue
November 29, 2018 at 3:42 pm
hello_san - Thursday, November 29, 2018 12:13 PMDoes anyone have a script to Capture all SQL Connection to table and schedule a job that deletes the entry from the table after 7 days?
The question not being asked, and needs to be, what are you trying to accomplish?
November 30, 2018 at 10:39 am
hello_san - Thursday, November 29, 2018 12:13 PMDoes anyone have a script to Capture all SQL Connection to table and schedule a job that deletes the entry from the table after 7 days?
Sounds like you should be using Extended Events to capture this kind of information. You can capture the code being executed (as was noted, there isn't a "connection to a table" to capture). I assume you're trying to track queries. This is one of the best ways to get it done. Another option since you're in 2017 is to use the Query Store.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
November 30, 2018 at 12:36 pm
not sure what you want it for, this is the best you can get, as suggested use extended events..
SELECT getdate() as datetime,
es.login_time,es.last_request_start_time,
ec.client_net_address, es.[program_name], es.[host_name], es.login_name, DB_NAME(eS.database_id) db_name,
COUNT(ec.session_id) AS [connection count]
FROM sys.dm_exec_sessions AS es WITH (NOLOCK)
INNER JOIN sys.dm_exec_connections AS ec WITH (NOLOCK)
ON es.session_id = ec.session_id
GROUP BY es.login_time,es.last_request_start_time, ec.client_net_address, es.[program_name], es.[host_name], es.login_name ,DB_NAME(eS.database_id)
ORDER BY ec.client_net_address, es.[program_name] OPTION (RECOMPILE);
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply