Logic Apps - SQL Connector returning cached data? - sql-server

I have a Logic App that uses the "SQL Server - When an item is modified (V2)" trigger, monitoring an Azure SQL DB for updated rows. When running this LA, I noticed that the modified row that came as output for this trigger did NOT contain the updated data.
I thought this might be by design (don't really see why, but ok...) so I added a "Get Row" action directly after the trigger, to go fetch the most recent data for the row that triggered the LA. But even this step still returned the old, not-updated data for that row.
However, when I resubmit the run some seconds later, the "Get Row" action does get the updated data from the database.
Is this normal behavior? Is the SQL DB row version already updated even though the data update isn't committed yet, triggering the Logic App but not returning the updated data yet?

Thanks for pointing me to add a timestamp to my table, I add the timestamp and then I can find the table in the selection. I test it in my side but the trigger works fine, it output the updated data. I provide my logic below for your reference:
My table show as:
My logic app:
Please note I disable the "Split On" in "Settings" of the trigger.
After running the update sql:
update Table3 set name = 'hury1' where id = 1;
update Table3 set name = 'jim1' where id = 2;
I got the result (the variable updateItems in screenshot contains both updated items):

Related

SQL Server + MS Access + triggers

I have a big difficulty in my front end MS Access application linked with a SQL Server database.
I have a form (Orders) with a subform (OrdersLines) in MS Access.
I have a trigger on the Orderslines table in SQL Server to calculate the total price, and others calculations.
In insert mode = everything is OK
When I want to update a column (Delivery town for example) the triggers process the new calculation correctly.
BUT the Form and SUB Form in access seems not get the information from the TRIGGER update.
That why at the end Afterupdate event of the field (Delivery town) i make a subform.refresh and form.refresh but with no effect on my problem.
THE PROBLEM : After the first update (delivery town), When I try to update any other column (Ref number) in the orders Form, an error 7878 occurs "Data have been modified". After that message, the update from database occurs and every thing goes well.
It seems that the refresh doesn't work in any event in access, the trigger seems to update the table at the very end of the process. Is that correct ?
Any idea to solve this ?
Thanks very much in advance for any help.
Best regards
Nic

Is there a limit for how many updated records an "for update" trigger can handle?

I am using Sql Server 2012 and I have a table that receives between 1000-1500 row updates per minute (amount seen in the Activity Monitor - Recent Expensive Queries). This updates come from Gps devices in different locations and the number seems about right (each line represents an active gps device sending updates).
I have wrote an extremely simple "for update trigger" after failing with more complex ones. The simple trigger doesn't seem to work either. The trigger should insert value "1" into a table ("Test") for each row updated in the table receiving the updates ("LiveInfo").
After creating and enabling the trigger I have observed the following:
- no records are inserted in the Test table (as i should have had a record containing value "1" for each row updated)
- it seems like the table LiveInfo (the one receiving the high number of updates) stops receiving updates when the trigger starts.
I have created tables and a trigger with the exact same structure on a local instance of SQLServer (although version 2016) and I tested everything with manual updates instead of automatic updates.
Everything seems to work fine using the simple trigger (even with way more complicated triggers).
The trigger code:
Create trigger t_Live
on [Accounting].[dbo].[LiveInfo]
for update
as
Begin
insert into Test
(TestUpdate)
values(1)
End
The different versions of SQL Server should not matter for such a simple trigger (from what I have researched) and I start to believe there might be too many updates (or maybe different rows being updated in almost exactly same time) for the trigger to handle.
If anyone has an idea why the trigger does not react to the updates and stops the updates all together would be a great help.
Edit: this is the code that updates the LiveInfo table. I got the query from Activity Monitor and has around 1300 Executions/Min:
UPDATE LiveInfo SET
[LogTimeUTC] = #logTimeUTC,
[Latitude] = #lat,
[Longitude] = #lon,
[Height] = #height,
[SolutionType] = #solType,
[TrackedSats] = #trackedSats,
[PDOP] = #pdop,
[MountPointName] = #mountPointName,
[FixedBEIDOU] = #fixedBEIDOU,
[FixedQZSS] = #fixedQZSS,
[FixedIRNSS] = #fixedIRNSS
WHERE [LoginWithOrganization] = #loginWithOrg

How do I update columns via SQL when a column has be changed? Kind of like a log! Microsoft SQL Server Management Studio

Okay, just to clarify: I have a SQL Table (contains ID, School, Student ID, Name, Fee $, Fee Type, and Paid (as the columns)) that needs to be posted on a Grid that will uploaded on a website. The Grid shows everything correctly and shows what Fees need to be Paid. The Paid column has a bit data type for 1 or 0 (basically a checklist.) I am being asked to add two more columns: User and DateChanged. The reason why is to log which staff changed the "Paid" column. It would only capture the Username of the staff who changed it in the SQL Table and also the time. So to clarify even more, I need to create 2 columns: "User, DateChanged" and the columns would log when someone changed the "Paid" column.
For example: User:Bob checks the Paid column for X student on 5/2/17 at 10pm.
In the same row of X student's info, under User column Tom would appear there. Under DateChanged it would show 2017-05-02 10pm.
What steps would I take to make this possible.
I'm currently IT Intern and all this SQL stuff is new to me. Let me know if you need more clarification. FYI The two new columns: User, DateChanged will not be on the grid.
The way to do this as you've described is to use a trigger. I have an example of some code below but be warned as triggers can have unexpected side-effects, depending on how the database and app interface are set up.
If it is possible for you to change the application code that sends SQL queries to the database instead, that would be much safer than using a trigger. You can still add the new fields, you would just be relying on the app to keep them updated instead of doing it all in SQL.
Things to keep in mind about this code:
If any background processes or procedures make updates to the table, it will overwrite the timestamp and username automatically, because this is triggered on any update to the row(s) in question.
If the users don't have any direct access to SQL Server (in other words, the app is the only thing connecting to the database), then it is possible that the app will only be using one database login username for everyone, and in that case you will not be able to figure out which user made the update unless you can change the application code.
If anyone changes something by accident and then changes it back, it will overwrite your timestamp and make it look like the wrong person made the update.
Triggers can potentially bog down the database system if there are a very large number of rows and/or a high number of updates being made to the table constantly, because the trigger code will be executed every time an update is made to a row in the table.
But if you don't have access to change the application code, and you want to give triggers a try, here's some example code that should do what you are needing:
create trigger TG_Payments_Update on Payments
after update
as
begin
update Payments
set DateChanged = GetDate(), UserChanged = USER_NAME()
from Payments, inserted
where Payments.ID = inserted.ID
end
The web app already knows the current user working on the system, so your update would just include that user's ID and the current system time for when the action took place.
I would not rely on SQL Server triggers since that hides what's going on within the system. Plus, as others have said, they have side effects to deal with too.

SQl-SERVER accidental update

Hi I have accidently updated a row in SQL-SERVER that I should not have is there anyway to get the previous value of the row using this query:
UPDATE Documents
SET Name = 'Files'
WHERE Id = 950
Is there any way to recover the previous value?
Yes, it is possible, but only under certain circumstances.
If you had wrapped the UPDATE in a transaction, you could ROLLBACK. This would undo the UPDATE.
Assuming you didn't put it in a transaction, you need to reset the database to a previous point in time. This is only possible if you have some form of back-up on the database. How to do this is shown in this MSDN page
Not that both of these options will UNDO the update, not just tell you the previous values.

how to update part of object

It is necessary to insert some data in DB once each web service method is called: in the beginning of the request processing and in the end.
My intention is to insert record that will contains all income information in the beginning of request processing and after that update the same record once request is processed and data are ready to be send back (or error is occurred and I is need to store error message).
The problem is that income data can be pretty long and LINQ To SQL before update need to fetch object data from DB and then "store" it again. In this case "income data" is going 3 times:
1st time when inserting - it goes into DB;
2nd time before object update - it is fetched from DB;
3rd time on update - it is going to DB again.
Is there any possibility to optimize such process if I already have object fetched from DB?
Is the same applied to Entity Framework? Does it allow to update only the part of object?
An ORM is geared towards converting complete rows to complete objects, and back again - so updates are always to the full object.
However, both Linq-to-SQL as well as Entity Framework are definitely smart enough to find out what properties have changed on an entity, so if you only update some fields, the generated SQL command using UPDATE will only update those changed fields.
So basically: you just try it! Fire up SQL profiler and see what SQL goes to the database; in Entity Framework, I'm positive that if you only change some fields, only those changed fields will be updated in an UPDATE statement and nothing else.

Resources