How can I monitor the quantity of active connections in SQL Server 2014 using SQL Server 2014 Management Studio?
SELECT * FROM sys.dm_exec_sessions
If active connections means those connections which are executing something right now then one solution is
sys.dm_exec_requests
https://msdn.microsoft.com/en-us/library/ms177648.aspx
"Returns information about each request that is executing within SQL Server."
To get count of active connections we can use:
SELECT COUNT(*)
FROM sys.dm_exec_requests
--Where status = 'Running'
Note: executing requests/statements can have a status. Please see doc for sys.dm_exec_requests.status column.
Related
I have an Application Server connected to a Database Server (running SQL Server 2014 Express)
I have the following query saved in saveEmails.sql on the Application Server
select
concat('<H3>Email sent: ',send_request_date,'</H3>',body)
from
msdb.dbo.sysmail_allitems
where
send_request_date > dateadd(day, -1, getdate())
order by
send_request_date desc
I have the following saved in a batch file on the Application Server
sqlcmd -S <ip,port> -y0 -U tomcat -P <password> -i saveEmails.sql -o
"C:\temp\saveEmailsOutput.htm"
I did GRANT SELECT ON msdb.dbo.sysmail_allitems to TOMCAT
When I run the query on the database server through SSMS, then I get all the rows in the table.
When I run the query on the application server through sqlcmd, then I only get the rows with sysmail_allitems.send_request_user=tomcat
How can I see all the rows and not just those with send_request_user=tomcat?
msdb.dbo.sysmail_allitems is a view and has Row-level security implemented, which limits the user who is viewing to those rows which were executed by that user.
Run the query instead on msdb.dbo.sysmail_mailitems which is a table and does not have Row-level security implemented.
Note that SQL Server 2014 does not support row-level security on tables, but SQL Server 2016 does.
How to find all the session for particular plan_handle or sql_hash in SQL Server?
I have tried to pull the SQL Services, Agent Service, SSRS Services running status. But I got only SQL, AGent services details am getting by using this query, Whereas I am not getting the SSRS, AS, IS services running status.
I have cross checked the services are up and running in the servers.
Query :- select * from sys.dm_server_services
Please help me
According to Microsoft:
sys.dm_server_services returns only information about the SQL Server, Full-Text, and SQL Server Agent services in the current instance of SQL Server, so this is the expected behaviour.
https://learn.microsoft.com/en-us/sql/relational-databases/system-dynamic-management-views/sys-dm-server-services-transact-sql?view=sql-server-2017
You could use a query that checks if the ReportServer database exists. This is the default database for SSRS. Of course this will fail if the SSRS was configured to use a custom name for its database.
IF EXISTS(SELECT * FROM sys.databases WHERE [name] = 'ReportServer')
PRINT 'SSRS seems to be installed'
Using Tsql, how can I find out when MS SQL server was installed?
The NT AUTHORITY\SYSTEM login is created when you install SQL Server, so:
SELECT createdate
FROM sys.syslogins
WHERE name = 'NT AUTHORITY\SYSTEM'
This will return an incorrect result however if you've ever restored the Master database.
It looks like the first 100 principal_id values are reserved in sys.server_principals (SQL Server 2005+). Based on what I see in one of my sys.server_principals (SQL Server 2005, SP3), I'd try this:
SELECT MIN(create_date) FROM sys.server_principals WHERE principal_id > 100
I'm currently using SQL 2000 (it's a vendor server - don't ask...), and I'm wondering if there's a way to detect the connection protocol of connected clients. For SQL 2005+, I use:
select net_transport from sys.dm_exec_connections
where session_id = ##spid
But SQL2000 lacks this dynamic view. Anybody know the equivalent function on SQL2000?
SELECT net_library FROM sysprocesses WHERE spid = ##SPID
You can also sys.sysprocesses in SQL Server 2005/2008. It may be deprecated but there is no equivalent in after SQL 2000 for functionality, says MS Connect 144515