Session connection full information - sql-server

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

Related

Debezium: No maximum LSN recorded in the database; please ensure that the SQL Server Agent is running

This question is related to: Debezium How do I correctly register the SqlServer connector with Kafka Connect - connection refused
In Windows 10, I have Debezium running on an instance of Microsoft SQL Server that is outside of a Docker container. I am getting the following warning every 390 milliseconds:
No maximum LSN recorded in the database; please ensure that the SQL
Server Agent is running
[io.debezium.connector.sqlserver.SqlServerStreamingChangeEventSource]
I checked Debezium's code on Github and the only place that I can find this warning states in the code comments that this warning should only be thrown if the Agent is not running. I have confirmed that the SQL Server Agent is running.
Why is this warning showing up and how do I fix it?
Note:
My current solution appears to only work in a non-production environment - per Docker's documentation.
LSN is the "pieces" of information related about your SQL Server changes. If you don't have LSN, is possible that your CDC is not running or not configured properly. Debezium consumes LSNs to replicate so, your SQL Server need to generate this.
Some approaches:
Did you checked if your table are with CDC enabled? This will list your tables with CDC enabled:
SELECT s.name AS Schema_Name, tb.name AS Table_Name
, tb.object_id, tb.type, tb.type_desc, tb.is_tracked_by_cdc
FROM sys.tables tb
INNER JOIN sys.schemas s on s.schema_id = tb.schema_id
WHERE tb.is_tracked_by_cdc = 1
Your CDC database are enabled and runnig? (see here)
Check if enabled:
SELECT *
FROM sys.change_tracking_databases
WHERE database_id=DB_ID('MyDatabase')
And check if is running:
EXECUTE sys.sp_cdc_enable_db;
GO
Your CDC service are running on SQL Server? See in docs
EXEC sys.sp_cdc_start_job;
GO
On enabling table in CDC, I had some issues with rolename. For my case, configuring at null solved my problem (more details here)
EXEC sys.sp_cdc_enable_table
#source_schema=N'dbo',
#source_name=N'AD6010',
#capture_instance=N'ZZZZ_AD6010',
#role_name = NULL,
#filegroup_name=N'CDC_DATA',
#supports_net_changes=1
GO
Adding more to William's answer.
For the case SQL Server Agent is not running
You can enable it by following :
Control panel >
Administrative Tools >
Click "Services"
Look for SQL Server Agent
Right click and Start
Now you can fire cdc job queries in your mssql.
PS: you need to have login access to windows server.
Another possibility of this error (I just ran into this warning myself this morning trying to bring a new DB online) is the SQL login does not have the permissions needed. Debezium runs the following SQL. Check that the SQL login you are using has access to run this stored procedure and it returns the tables you have set up in CDC. If you get an error or zero rows returned, work with your DBA to get the appropriate permissions set up.
EXEC sys.sp_cdc_help_change_data_capture

DB Link from Oracle to MS Server

I am new to this forum and already searched for 45 minutes to find a solution for my problem. I hope you can help me.
A Gateway to a remote Microsoft SQL Database was installed on a Oracle Server (Oracle 12c). The tsnnames.ora file was appropiately set up.
For the connection, I created a database link (In the Oracle DB) as follows:
CREATE DATABASE LINK TEL CONNECT TO "fb_B2C" IDENTIFIED BY "passwort" USING 'dg1msql';
When I now execute the Select statement:
SELECT "name" FROM "sys"."databases"#TEL
it shows me the according databases. Among others, I can see the AB_Colors database.
Now, I want to select a view in the AB_Colors database.
Due to the fact I can connect to this database via Excel, I know that in the database AB_Colors, there are 10 Views(A,B,C,..). I would like to select the View C from the database AB_Colors via the DB LInk.
Owner of the View is b2b.
How do i need to formulate the select statement to do it?
I already tried different writings:
SELECT * FROM b2b.C#TEL;
SELECT * FROM "AB_colors"."b2b"."C"#TEL;
SELECT * FROM [AB_Colors].[b2b].[C]#TEL;
The common error message is: View/Table does not exist
I highly appreciate your help,
Fedja
This is the correct format
SELECT * FROM "b2b"."C"#TEL;
The issue maybe because the database you want to select from is not the one specified in the gateway for dg1msql. You can't add the database name to the query so you must specify it in the gateway connection.
This is defined in
$ORACLE_HOME/dg4msql/admin/initdg4msql.ora
where you should check HS_FDS_CONNECT_INFO

SQL Server Management Studio Express not showing recently added data

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

Data sync check among two SQL Server database

We've two SQL server database. The source server has data populated from an external system and a destination database on a remote server (used by a web app). There's an SSIS package which maps column from source tables to destination (column names differ) and populates data to maintain the sync.
Now, to ensure that both the database are in sync for which we've an SP which shows record count and for some parent-child relationships it shows child count for each parent record (i.e. Brandwise Item count). Someone has to logon to both the servers, execute the SP and get the data manually. Then compare the results to ensure that both the db are in sync.
Now, to automate this process, we've done the following-
Add the destination server as a "Linked Server"
Use "EXEC msdb.dbo.sp_send_dbmail" along with "#attach_query_result_as_file =1"
Create an SSIS job which will execute the email SP for both the servers
So, this is how we get two emails which has query results attached to
it. And then comparing the text files completes the db sync check.
I believe this can be made better - now that we're able to access the destination server as a linked server. Its my first time so I'd request some experienced guys to share their approach, probably something beyond a join query with the linked server.
Since you have access to server as Linked server you can directly run query and compare data.
Please check this
You can modify SSIS jobs to send mails based on this query result.
I'm using the following query which is a simple version and gives me differences of both the sides -
(Select s.Title, s.Description from ERPMasterBrand as s EXCEPT
Select d.Title, d.Description from MasterBrand as d)
UNION
(Select s.Title, s.Description from MasterBrand as s EXCEPT
Select d.Title, d.Description from ERPMasterBrand as d)
Any better suggestions? I've tested and it gives desired results - hope I'm not being misguided :-) by my own solution.

On SQL Server 2008, how to find out when was any database offline/online?

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

Resources