Windows server 2016: Instances monitoring - sql-server

I have very general question, we are a bunch of analytical consultants. We use same server with multiple instances. Is there a way I can track which instance is opened by which desktop user?
Thanks for your time.
This is what I see on my taskManager:
Is there a way I could know the desktop username, who is on which instance. Please let me know the workaround. Thank you so much.

if you are refer to user instance that connect to a same server via RDP
you can check user session information on task manager > user tab
if you are refer to which process instance is run by which users
then you can go to task manager > Details tab

You can create a linked server for all of your instances and call a query like this:
SELECT DISTINCT 'INSTANCE 1', loginame, hostname, dbname
from openquery(LINKEDSERVER1,'EXEC sp_who;')
UNION
SELECT DISTINCT 'INSTANCE 2', loginame, hostname, dbname
from openquery(LINKEDSERVER2,'EXEC sp_who;')
For more information about how to create a linked server, please check https://sqlserverplanet.com/dba/how-to-add-a-linked-server

Related

How to get session history in Azure sql server?

Someone deleted my azure database tables and procedures. Now I want to know from which workstation/ip this has happened.The person used db owner Id.
Azure portal activity logs don't give any details as deletion is done through sql queries.
I know how to see active sessions in sql service, but I want the history of sessions that existed in last 3 days with my database. Please help!
Using the below query can find the history of connection sessions, but it only can shows the local client IP address:
SELECT connection_id,
c.client_net_address,
c.session_id,
connect_time,
client_net_address,
client_tcp_port,
host_name,
program_name,
login_name,
row_count
FROM sys.dm_exec_connections c
JOIN sys.dm_exec_sessions s ON s.session_id = c.session_id
You will get the results like this:
Maybe it can help you know from which workstation/ip this delete operation has happened
Hope this helps.

How to create trigger to block certain program name except if the login is within a specific AD group?

I need to be able to stop Microsoft Office applications from connecting to my SQL database except if the login used is part of a specific AD group.
Only those within said AD group should be able to connect to the database with any Office application. This is even possible?
SQL Server 2012 Enterprise.
I know they're configured for the whole server, but I'm thinking of creating a trigger. I've created a table that is constantly updated with the AD users and created the below join. What I need is for everyone that is returned by this query to access the database with their desired Office app, and everyone who isn't returned to be rejected.
SELECT A.LOGIN_NAME, A.PROGRAM_NAME, B.LOGIN NAME
FROM sys.dm_exec_sessions A
JOIN AD_Group_Members B ON A.login_name = B.LOGIN NAME
WHERE session_id = ##SPID
AND program_name IN (N'2007 Microsoft Office system', N'Microsoft Office', N'Microsoft Office 2016', N'Microsoft Office 2013', N'Microsoft® Mashup Runtime')
I can't test this because I cannot get my hands of an adequate testing environment :/
So, would this work? Is there a better way of conducting this?
I know how to write the trigger, I'm just looking at getting the meaty bit right as I don't fancy blocking the wrong connections on a production box.

Azure PaaS logical server Create time

Anyone knows how to get the "logical server" create time? I'm unable to find this in any Azure cmdlet.
You could get it from Activity log.
Update:
Activity log is limited to 90 days. Another way you could find Deployments templates in Azure Portal.
In SQL, you could use following sql query to get creation data.
SELECT name, database_id, create_Date, compatibility_level FROM sys.databases
Please check this link.

SSRS 2012 Subscriptions - Credentials used to run this report are not stored

I'm trying to create a subscription on an SSRS 2012 report, working from a SQL Server 2008 database. From what I've read elsewhere, if I store the credentials in an individual report / stored datasource in the Report Manager, I should be able to create a subscription.
Unfortunately, for some reason this isn't happening for me. I have tried storing the credentials in a single reports, and also creating a datasource with stored credentials, with no luck (the 'Test Connection' button shows a successful connection). Please see screenshots.
Can anyone suggest what else I may still need to do to successfully create subscriptions?
Thanks,
Gavin
The problem you are having is that the credentials are not stored in the report itself. You will need to go into the report and right click on the data source and oull up properties then you will need to have a SQL Account that has rights to the data and then open the credentials tab and enter the username and passowrd in the blanks provided then be sure to click remember credentials then you should be able to set-up a subscription with no problem.
Since youa are using subscriptions the report itself needs a user name to runit as. WHat you are trying to do here is create a data source for the folder to use. But the data source being used by the report is a seperate connection.
I both embedded the data in the report as suggested by Wes Palmer (thanks) and used a specific SQL server account rather than integrated security. I then needed two further steps:
1.) Add a 'Report Server' entry into the msdb 'syscategories table as follows:
sp_configure 'allow update', 1
go
reconfigure with override
go
SET IDENTITY_INSERT syscategories ON
go
insert into syscategories(category_id, category_class, Category_type, Name) values(100, 1, 1, 'Report Server')
go
SET IDENTITY_INSERT syscategories OFF
go
exec sp_configure 'allow update', 0
go
reconfigure with override
go
2.) I set the SSRS Service account to a domain admin account.

Get list of databases user has access to

I have a SQL Server 2008 instance with several databases and I'm currently writing a C# application to access those databases. In this app, the end user can select a database they want to connect to.
I already have a list of all databases on the server, how can I limit that list to those databases the user can log in to? Or, how can I query that list?
There's a lot of databases, but each user can only access some of them, so trying to connect and catching the Exception is probably not a good idea.
Fyi: The server is configured for Windows authentication only, and the logins to the server are created for Windows' user groups (not individual users).
You can query all databases from sys.sysdatabases, and check if the user has access with HAS_DBACCESS:
SELECT name
FROM sys.sysdatabases
WHERE HAS_DBACCESS(name) = 1
Maybe as an alternative to Andomars answer (which I like!) you could interrogate Active Directory to see if the user is a member of a valid group for your database. I suspect this would mean you would have to maintain some Windows Group to Database Name lookup.
You can use the system stored procedure sp_helplogins 'User Name'

Resources