1
How can I get one back select
of a trigger
?
Example:
CREATE TABLE PESSOA2
(
ID INTEGER IDENTITY NOT NULL,
NOME VARCHAR(250)
)
CREATE TRIGGER SELECIONAR_NOME2 ON DBO.PESSOA2
AFTER UPDATE AS
BEGIN
SELECT * FROM PESSOA2
END
INSERT INTO PESSOA2 (NOME) VALUES ('fulano1')
INSERT INTO PESSOA2 (NOME) VALUES ('fulano2')
INSERT INTO PESSOA2 (NOME) VALUES ('fulano3')
INSERT INTO PESSOA2 (NOME) VALUES ('fulano4')
INSERT INTO PESSOA2 (NOME) VALUES ('fulano5')
UPDATE PESSOA2 SET NOME = 'fulano0' WHERE NOME = 'fulano1'
Result after giving UPDATE:
In this example, when I give one update
he gives a select
on the table pessoa
, what I want to know is how I can recover the select
via application c#?
Using try
{}catch
{} I can get an error return, but how to recover select table?
EX to get return:
try
{
identity = dbCommand.ExecuteXmlReader().toInt32(); //Não conseguiu exercutar? Gera uma Excepition gera um log para análise
} // e procura por outra Exception.
catch (Exception e)
{
if(e.Message == "Comando inválido enviado a ExecuteXmlReader. O comando deve retornar um resultado Xml.")
{
return;
}
MessageBox.Show(e.Message, "Exceção banco de dados");
}
recover the select? what you mean by that?
– HudsonPH
Hudsonph type, when I update the personal table2 Trigger is triggered, and then make a table select, as I can recover this select via application c#?
– Gustavo Pedro
but what is the need for it? wouldn’t it be better to implement in your service the select returning the new values? pq Trigger + c# 'e to Realtime app
– HudsonPH
I want to update a
DataGridView
, I have fields with multiple users and Status(online or offline)DataGridView
Currently I did withTimer
, but it gets bad, updating every time... : D Know a better way? Help me Please... : D– Gustavo Pedro
use that nuget https://github.com/christiandelbianco/monitor-table-change-with-sqltabledependency
– HudsonPH
I’ll check... a moment
– Gustavo Pedro
Do I still not understand? First of all
Trigger
means trigger, male noun, meaning the Rigger is just a trigger fired after a DML event. Second triggers are not used in this way they are mechanisms of propagation of changes, for fields, other tables or other databases, activated after and only the change to which they were associated. Third the only way to recover the cursor for that select create a cursor for that select withDECLARE CURSOR
and then open it withOPEN
and scroll through that cursor withFETCH
. Continues...– Augusto Vasques
The problem of this operation is not the difficulty and time it takes to implement it but the impact it causes on the memory and performance of the database server because for each cursor of a
SELECT *
aMIRROR
of the table in question within the server for each active cursor. That said, I ask. It wouldn’t be easier after your UPDATE command makes a SELECT within C#?– Augusto Vasques
I took a look at
Solution
that you sent Hudsonph and I couldn’t understand her, she’s very confused and complex.– Gustavo Pedro
Hello Augusto, thanks for the answer, so the application I am creating will run several times, imagine the scenario: 10 machine running it, I need to know which of these machines are logged in the application. I did that when logging in an update in the person table and changing your STS to = online. When a person logs in I need to update a Preview menu that will run on another machine, as I will update it?
– Gustavo Pedro
I did with
Timer
, every 15 seconds make select in the table and update theDataGridView
. Only with this it takes time to update and will be updating even if general is Offline. I thought to do with Trigger, when some client update the table and change their STS, then I identify this change and give sselect in the table, ensuring that only when someone gets online or offline again I update theDataGridView
– Gustavo Pedro
I’ll repeat @Hudsonph’s reply, use the component Sqltabledependency. Just install the package via Nugget and use in your application.
– Augusto Vasques
Another if you just know who is online and offline is not easier to use the sp-who
– Augusto Vasques
So, it would be interesting, would know status when connecting with the server, but I’m not a developer, I’m just doing a small project, I thought it would be easier to solve my problem
– Gustavo Pedro
I couldn’t install Nugget.exe it seems that you have to configure an environment variable to be able to run it and dps install it, I can’t install the package through Visual Studio?
– Gustavo Pedro
put an answer and functional example, just need to change model and Connection to test
– HudsonPH
??? Nugget.exe??? Menu Tools->Nuggets Package Manager->Manage Nugget Package for Solution...
– Augusto Vasques
It has instator, but the look has this hand on the wheel kkkk I will install here
– Gustavo Pedro
I think to install you need another version of . Net use 4 for the application
– Gustavo Pedro