ANY IDEA ?
I have Sql Server Enterprise 64 need to find:
The last time the SQL Server DB have been accessed (time)
Detailed information (the inventory) of all applications and/or users accessing the DB.
Explanation: I am doing an inventory of all my databases (around 120) which would help me decide whether to keep the DB and that will help me a decision about: If the DB should be kept or consolidate it with another one.
I have been working with thise Scripts below but they are limited
1 not working on 2000-05. I need more details like program name, statut, hostname, userinfo ...
2-Need last used info
May be both needed to be combined and refined.
Script 1
WITH last_query_by_db (dbid, Last_query)
AS (select dbid, max(last_execution_time) 'Last_query'
from sys.dm_exec_query_stats
cross apply
sys.dm_exec_sql_text(plan_handle)
group by
dbid
)
select d.name, Last_query
from
sys.databases d
left outer join
last_query_by_db q on q.dbid = d.database_id
where d.name not in ('master','msdb','model','tempdb')
order by 1
Script 2
SELECT HOSTNAME, PROGRAM_NAME, STATUS, SPID
FROM MASTER..SYSPROCESSES
WHERE DBID= DB_ID('TestDB')
AND SPID != ##SPID
You can enable Login Auditing in SQL Server Management Studio. After that, you can see the logs like this:
In Object Explorer, expand a server, expand Management, and then expand SQL Server Logs.
Right-click a log and click View SQL Server Log.
Source: MSDN
To check for the application name, use SELECT APP_NAME(). (Source)
Also, there is an Activity Monitor in SQL Server that can provide valuable information:
Implement an audit session (enterprise ed only) or xevents session (which version are you on?) or logon trigger.
Here's how to implement a logon trigger:
http://technet.microsoft.com/en-us/library/bb326598.aspx
Related
session Connection full information
I am currently running the query and capturing session connection information which collects login, NT User, Host, Application/Program, Server and database information but i am also looking more granular detail which also tell me if it's executing SSIS package then which SSIS package, if it's tableau reports as application/program then which Database objects it's pulling the reports or other application/batch job doing any DML activities.
If i can't get all the above details but as a example if it's running SSIS package then which SSIS package running i can get it?
I am running currently couple different query as a daily sql job and storing the data into table.
SELECT ##ServerName AS SERVER
,NAME
,login_time
,last_batch
,getdate() AS DATE
,STATUS
,hostname
,program_name
,nt_username
,loginame
FROM sys.databases d
LEFT JOIN sys.sysprocesses sp ON d.database_id = sp.dbid
WHERE database_id NOT BETWEEN 0 AND 4
AND loginame IS NOT NULL
Any other way i can more details as we will be doing migration wanted to make sure?
Ex. If SSIS loading data into DB, we need to find that SSIS package
Currently I am able to identify all connections established to the instance and where they are coming from, but
we need to know which of those connections are feeding data and which are consuming data.
Thanks for all your help!
The simple answer is No.
When an application connects, it can have an ApplicationName passed in the connection details. You can retrieve it easily enough from the program_name column when you query sys.dm_exec_sessions. But it has to be configured in the connection string (in the SSIS data source) for you to be able to retrieve it.
Adding an ApplicationName to your connection strings is a good habit, not just for this, but for many tuning/monitoring reasons.
You can query the SSISDB catalog system view, catalog.executions, to find SSIS package executions on the server:
SELECT * FROM ssisdb.catalog.executions
I recently installed and have been using Microsoft SQL Server Management Studio Express 9.00.4035.00 to manage a remote database on my hosts' SQL Server 2005.
Until now I had been using EMS SQL Manager 2011 Lite and that was working fine.
2 new rows where inserted into one of my tables this morning; one by a customer signing up for a service and the other as a test signup by me.
When I run a typical select query:
[Select top 20 * From tblNotary Order By ID Desc]
I don't see the the 2 most recent rows. But when I run the same query from EMS SQL Manager Lite I see the records.
I also verified when connecting using MS Access 2010 I see the 2 new rows in the table. I have checked and double-checked the connection settings and they match EMS.
Is there a setting or something obvious I am missing? Why can't I see the most recent record insertions? I am on a Windows 7 desktop machine.
The most likely reason is you are connecting to a different database than you expected. You can select ##servername to verify both queries are running against the same server.
If the records are stil being inserted as part of an open transaction and have not been committed, they are called "phantom" rows. You will not see phantom rows if your query runs at transaction isolation level read committed or higher. It may be that EMS SQL Manager Lite is running at read uncommitted, in which case it will include phantom rows in the query.
Sometimes connection strings are a tricky thing. Run this to double check:
select ##servername servername, name, crdate
from sys.sysdatabases
where name = db_name()
if you have an issue running that, just do a simpler version:
select ##servername, db_name(), ##version
Select top 20 * From tblNotary Order By ID Desc
We have this recurring situation where several times a week our application stops responding. What I would like to do is be able to view the text of the query running on SQL Server.
I can use sp_who to see the open connections, but, it does not display the actual query text.
If I can see the query that is freezing my database I can have a starting point for optimization.
This happened a few minutes ago and our sys admin had to reboot the box. This rebooting is not sustainable.
What steps should I take?
I would like to see the actual text of the queries that are running on my server.
SQL Server 2000
use this while the block is happening:
SELECT
r.session_id AS spid
,r.cpu_time,r.reads,r.writes,r.logical_reads
,r.blocking_session_id AS BlockingSPID
,LEFT(OBJECT_NAME(st.objectid, st.dbid),50) AS ShortObjectName
,LEFT(DB_NAME(r.database_id),50) AS DatabaseName
,s.program_name
,s.login_name
,OBJECT_NAME(st.objectid, st.dbid) AS ObjectName
,SUBSTRING(st.text, (r.statement_start_offset/2)+1,( (CASE r.statement_end_offset
WHEN -1 THEN DATALENGTH(st.text)
ELSE r.statement_end_offset
END - r.statement_start_offset
)/2
) + 1
) AS SQLText
FROM sys.dm_exec_requests r
JOIN sys.dm_exec_sessions s ON r.session_id = s.session_id
CROSS APPLY sys.dm_exec_sql_text (sql_handle) st
WHERE r.session_id!=##SPID
this will list all active SPIDs, who is blocking them and the SQL of each SPID
EDIT
this query is for SQL Server 2005+, initial question did not state SQL Server 2000
See the article How to monitor blocking in SQL Server 2005 and in SQL Server 2000 for the definition of sp_blocker_pss08 (a SQL Server 2000 compatible script).
I have to include one report in my application showing offline/online activity of few databases on SQL Server 2008.
Could you please suggest how can I collect teh same information from sql server?
SELECT DATABASEPROPERTYEX('YOURDATABASE', 'Status')
DatabaseStatus_DATABASEPROPERTYEX
GO
SELECT state_desc DatabaseStatus_sysDatabase
FROM sys.databases
WHERE name = 'YOURDATABASE'
GO
This will tell you the status of the database.
In order to find out when your database was taken OFFLINE, you can use the SQL that I posted before, or the easiest way is to check the Event Viewer and it will tell you when the Database was taken OFFLINE. I have just tested this on my local machine and SQL Server writes out an Information message to the Application log.
You can also use below query to check database status.
SELECT Name, state_desc FROM sys.databases
I need to get a log of user access to our SQL Server so I can track average and peak concurrency usage. Is there a hidden table or something I'm missing that has this information for me? To my knowledge the application I'm looking at does not track this at the application level.
I'm currently working on SQL Server 2000, but will moving to SQL Server 2005 shortly, so solutions for both are greatly appreciated.
In SQL Server 2005, go to tree view on the left and select Server (name of the actual server) > Management > Activity Monitor. Hope this helps.
on 2000 you can use sp_who2 or the dbo.sysprocesses system table
on 2005 take a look at the sys.dm_exec_sessions DMV
Below is an example
SELECT COUNT(*) AS StatusCount,CASE status
WHEN 'Running' THEN 'Running - Currently running one or more requests'
WHEN 'Sleeping ' THEN 'Sleeping - Currently running no requests'
ELSE 'Dormant – Session is in prelogin state' END status
FROM sys.dm_exec_sessions
GROUP BY status