How to start sql server extended events sessions using sql query - sql-server

I am able to create SQL Server Extended events session using sql query.
But following are the two issues i am facing while creating Extended events session using sql query
Extended events session gets created in disabled(stop) state.
.xel file is not getting created at specified location.
I noticed while creating extended events using wizard initially extended event is created in disabled(stop) state and on selecting "Start event session immeditely...." session is set to start state and .xel file is created.
I want to implement this same step using sql query.
Following is my script
CREATE EVENT SESSION [LoginSession_History] ON SERVER
ADD EVENT sqlserver.connectivity_ring_buffer_recorded(
ACTION(sqlserver.client_app_name,sqlserver.client_connection_id,sqlserver.client_hostname,sqlserver.context_info,sqlserver.database_name,sqlserver.nt_username,sqlserver.plan_handle,sqlserver.query_hash,sqlserver.query_plan_hash,sqlserver.server_principal_name,sqlserver.session_id,sqlserver.sql_text)),
ADD EVENT sqlserver.login(SET collect_options_text=(1)
ACTION(sqlserver.client_app_name,sqlserver.client_connection_id,sqlserver.client_hostname,sqlserver.context_info,sqlserver.database_name,sqlserver.nt_username,sqlserver.plan_handle,sqlserver.query_hash,sqlserver.query_plan_hash,sqlserver.server_instance_name,sqlserver.server_principal_name,sqlserver.session_id,sqlserver.sql_text)),
ADD EVENT sqlserver.logout(
ACTION(sqlserver.client_app_name,sqlserver.client_connection_id,sqlserver.client_hostname,sqlserver.context_info,sqlserver.database_name,sqlserver.nt_username,sqlserver.plan_handle,sqlserver.query_hash,sqlserver.query_plan_hash,sqlserver.server_instance_name,sqlserver.server_principal_name,sqlserver.session_id,sqlserver.sql_text))
ADD TARGET package0.event_file(SET filename=N'D:\Ext_Events\LoginSession_History.xel'),
ADD TARGET package0.ring_buffer
WITH (MAX_MEMORY=4096 KB,EVENT_RETENTION_MODE=ALLOW_SINGLE_EVENT_LOSS,MAX_DISPATCH_LATENCY=30 SECONDS,MAX_EVENT_SIZE=0 KB,MEMORY_PARTITION_MODE=NONE,TRACK_CAUSALITY=ON,STARTUP_STATE=ON)
GO

Use STATE = start; via altering the EVENT SESSION as next
-- Start the event session
ALTER EVENT SESSION test_session
ON SERVER
STATE = start;
GO
Reference from official site

To fix this , we need to use Alter event session command and pass STATE=start
Following is the link
https://www.concurrency.com/blog/december-2015/schedule-extended-events-session-start-or-stop

STARTUP_STATE=ON
Refers to the state that will used when the sqlserver service instance is restarted.
It determines whether it will be auto-started or not.
Whether to set ON|OFF depends on the type of event tracing you want to perform & whether you want it activate across recycles.
An invasive trace that consumes many cpu cycles whilst logging lots of detail would be very unwelcome at startup in most places.

Related

How can I populate a combobox from a SQL Server database server in Delphi?

First of all, I'm new to Delphi, and I checked all the relevant threads on here, but nothing seems to be working.
I'm just trying to fill a TComboBox with values of a column from a SQL Server database.
So basically, I have a VCL form and a DataModule, which holds an ADOConnection and an ADOQuery. The ADOConnection connects to my database (test connection says it's successful) and the ADOQuery connects to my ADOConnection. The VCL form and the DataModules are "connected".
(And actually here comes another problem: whenever I'm trying to enter SELECT name FROM Partners; in the properties of my ADOQuery and try to set it active, it keeps saying "Invalid object name 'Partners'". The SQL statement is correct, I tested it in SSMS and it retrieves the data without any error. But I'm not sure if it's the main issue here).
So basically, here's my code:
procedure TFormInsertNewItem.ComboBoxPartnersDropDown(Sender: TObject);
begin
with DataModule1 do
begin
ComboBoxPartners.Items.Clear;
ADOQueryFillPartners.SQL.Clear;
ADOQueryFillPartners.SQL.Add('SELECT name FROM Partners;');
ADOQueryFillPartners.Active:=true;
ADOQueryFillPartners.Open;
while not ADOQueryFillPartners.Eof do begin
ComboBoxPartners.Items.Add(ADOQueryFillPartners.FieldByName('name').AsString);
ADOQueryFillPartners.Next;
end;
ADOQueryFillPartners.Active:=false;
ADOQueryFillPartners.Free;
end;
end;
Whenever I click to drop it down (or maybe it would be better if this runs when the form is loaded, but I have no idea how can I exactly refer to that event), it should fill it up. Well, it won't. I tried it with TDBComboBox and TDBLookUpComboBox, with setting their datasource, but it only added 1 item to the combobox.
Can anyone help me with what I messed up and how can I get it to work, please?
You have multiple problems in the code you've posted.
Clearly, the first thing you have to do is to get your query to open properly. If you can't run the query to get the data, you can't use that data to populate the combobox. Test your ADOConnection on your datamodule to see if you can connect to the database by setting its Connected property to True.
If that doesn't work, then you need to set up your ConnectionString properly. (Make sure you set the Connected property back to False. You should be connecting in your datamodule's OnCreate event, and disconnecting in the datamodule's OnDestroy event.)
If it does work, check to make sure you set the ADOQuery's Connection property to point to your ADOConnection, and then use the ADOQuery.SQL property to enter your SQL statement. Once you've done that, set the ADOQuery.Active property to True. (Again, don't forget to set it back to False and open it in your code at runtime.)
Next, you've used the wrong event. You should be doing this in the form's OnCreate event instead.
Also, you don't need both Active and Open for the query. They do the same thing; the only difference between them is that Active is a Boolean property that can be tested (if Query1.Active then) while Open is simply a method. There's no reason to open a query that's already active or make a query active that's already open.
In addition, you free the query at the end of your method, which means that the next time the combobox OnDropDown event is called, you're accessing an invalid class instance, which will cause an access violation.
And finally, you should be calling BeginUpdate before clearing and populating the combobox, and then EndUpdate when you're finished.
A more correct version of the code would be something like
procedure TFormInsertNewItem.FormCreate(Sender: TObject);
begin
with DataModule1 do
begin
{
I'm not sure why you're doing this at all. If you set the ADOQuery.SQL property
at designtime, and it never changes, you can remove the next two lines.
}
ADOQueryFillPartners.SQL.Clear;
ADOQueryFillPartners.SQL.Add('SELECT name FROM Partners;');
ADOQueryFillPartners.Active:=true;
try
ComboBoxPartners.Items.BeginUpdate;
while not ADOQueryFillPartners.Eof do begin
ComboBoxPartners.Items.Add(ADOQueryFillPartners.FieldByName('name').AsString);
ADOQueryFillPartners.Next;
end;
finally
ComboBoxPartners.Items.EndUpdate;
end;
ADOQueryFillPartners.Active:=false;
end;
end;

SSIS Logging - Capture Variables?

I'm trying to capture the values of about 15 variables within my sysssislog when my package executes.
I have set all the variables to true for "Raise event when variable value changes" and I understand I have to put some sort of object/code into the Event handler but I'm totally unsure as to what this should look like for the 15 variables.
Can anyone offer some examples please?
After the RaiseChangedEvent property is set to true on the variable the OnVariableValueChanged event will need be selected for logging to SYSSSISLOG. This can be done by right-clicking the package and selecting Logging then going to the Details tab and checking the check-box for the OnVariableValueChanged event. After this click the Advanced button and check the box for each element that will be logged, for instance Computer, SourceName, etc. To see the actual value that the variable was changed to query the SSISDB.CATALOG.EVENT_MESSAGES DMV following package execution. The MESSAGE column will show the value that the variable was set as during package execution.

Show All Instances That Should Be Dynamically Registered With a Listener

Is there a way in Oracle to show which instances should dynamically register by default with a certain listener?
I can do
lsnrctl status | grep Instance
and this will show me the currently running instances that are registered with that particular listener. But this will not display the instances that are not running.
In more detail:
Lets assume I have:
INSTDEV1 (up), INSTDEV2 (up), INSTDEV3 (down) registered with LISTENER_HOST1_DEV
and INSTSTG1 (up), INSTSTG2 (up), INSTSTG3 (down) registered with LISTENER_HOST1_STG
Is there a straightforward way to find out that the first three instances should register with LISTENER_HOST1_DEV
and the second set - with LISTENER_HOST1_STG
lsnrctl status LISTENER_HOST1_DEV & lsnrctl status LISTENER_HOST1_STG will show only INSTDEV1, INSTDEV2, INSTSTG1 and INSTSTG2, not the non-running instances.
Thanks.
1st way:
You can check oratab file at
/etc/oratab or /var/opt/oracle/oratab
For all the instances
And login to each of the database and check for the local_listener parameter is defined or not.
show parameter local_list
It will be defined in Dynamic mode.
2nd way:
If you have created 12c database with dynamic listener option your tnsnames.ora file will have separate listener entries defined for each database in the format
LISTENER_SID along with your tnsentries
I don't know of any other method.
Hope this helps.

using connection manager with orm cakephp 3

Every tutorial or documentation regarding this subject is used with sql queries but never with new orm.
I have two data sources defined in config/app.php: default and not_default
with same tables and columns, when the user login the default database is connected.
when the user clicks a certain button i need to change the connected database to not_default:
I achieved this so far:
ConnectionManager::get('default')->disconnect();
ConnectionManager::get('not_default')->connect();
ConnectionManager::get('not_default')->begin(); //dont know if required
when doing this: echo ConnectionManager::get('not_default')->isConnected(); I get 1 for not_default and 0 for default so it is connected
but the problem is when getting the model's TableRegistry the connectionname is still the default one!! How to change it???
I want to be able to get data using orm from database other than the default one.
You can use ConnectionManager::alias().
Connection aliases allow you to rename active connections without overwriting the aliased connection.
ConnectionManager::alias('not_default','default');
//from now on, all calls to default will resolve to not_default datasource

Customizing Mail Message in SSIS Event Handler

I want to add an email notification to an SSIS 2005 package event handler. I've added a Send Mail task to the event handler. I'd like to customize the email body to include things like the error description. I've tried including #[System::ErrorDescription] in the MessageSource field, but the mail message doesn't include the value of ErrorDescription only the name of the variable.
In the dialog for the Send Mail Task, select the word Mail in the list on the right. This brings up the property page for the Mail task. Set the MessageSourceType value to Variable and set the MessageSource to the name of the variable you want to use in the format System::ErrorDescription. This is how I used this component in SQL server 2005. I believe that the steps are similar in 2008, but it has been a while since I worked at a 2008 client, so I am working from memory there.
I think you are using MessageSource property in mail tab. You need to go to expressions then in the property select MessageSource and browse for expression button, there you can drag and drop #[System::ErrorDescription] variable into Expression text area.
Click on Evaluate expression it should not give any error message and you are done.
The name of the failed task is inthe system variable
System::SourceName

Resources