Duplicate Record Fetching from Load Balancer System - sql-server

One windows service is installed on two servers for load balancing. Both server nodes pointed to a single SQL Server database. How can we avoid duplicate records fetching from two server nodes? Following the solution is provided. But sometimes it fails.
Instance ID and timestamp column added in the table.
Instance ID and time stamp will update during service are trying to fetch the data.
Update the time stamp only if the timestamp column is null. Otherwise, it's not getting an update.
The instance ID is always updated during fetching the records. As per our system architecture, we cannot restrict the record to a single server instance ID.
UPDATE MyTable
SET TimeStamp= (case when TimeStamp is null then #TimeStamp else TimeStamp end),
instanceID = #p_InstanceID
Any solution to avoid duplicate fetching during two servers trying to access the same records.

Related

SQL SERVER Triggers interfere in MS-Access [duplicate]

My application is a front end MS Access application linked to a SQL Server database.
I have a form in MS Access for the Orders table and a sub form for Orderslines table
In the OrdersLines table, there is a trigger which calculates the total sum (Quantity x unit price) and more.
The "funny" thing, in MS Access, when I create a new order, I cannot modify the Orders table, because the database and access have not the same data.
So when I run me.requery in MS Access after the process of new order creation, the me.requery sends me to a new record.
This is not happening when I modify this command.
I have tried many things but I can't get it working to keep the current record with a new command.
Any idea will be welcome
Nico
The easiest way to solve this problem is to add a single TimeStamp field to each of your SQL Server tables.
Microsoft Access can track the changes to records in SQL by the TimeStamp field, and it will automatically requery the data from SQL Server and eliminate the "The Data has been modified by another User" message.
The field you add can have any name you wish (I use the name tsJET as this field specifically helps the JET/ACE engine track record changes in this case) and the type for the field is TimeStamp. You don't have to include this field in any queries or forms, it simply needs to exist in the table.
Be sure to refresh the table links after adding this field to your SQL Server tables so that Access can "see" the structural changes to the tables.
NOTE: You cannot modify the data in the TimeStamp field. SQL Server handles that automatically.

SQL Server triggers + MS Access forms

My application is a front end MS Access application linked to a SQL Server database.
I have a form in MS Access for the Orders table and a sub form for Orderslines table
In the OrdersLines table, there is a trigger which calculates the total sum (Quantity x unit price) and more.
The "funny" thing, in MS Access, when I create a new order, I cannot modify the Orders table, because the database and access have not the same data.
So when I run me.requery in MS Access after the process of new order creation, the me.requery sends me to a new record.
This is not happening when I modify this command.
I have tried many things but I can't get it working to keep the current record with a new command.
Any idea will be welcome
Nico
The easiest way to solve this problem is to add a single TimeStamp field to each of your SQL Server tables.
Microsoft Access can track the changes to records in SQL by the TimeStamp field, and it will automatically requery the data from SQL Server and eliminate the "The Data has been modified by another User" message.
The field you add can have any name you wish (I use the name tsJET as this field specifically helps the JET/ACE engine track record changes in this case) and the type for the field is TimeStamp. You don't have to include this field in any queries or forms, it simply needs to exist in the table.
Be sure to refresh the table links after adding this field to your SQL Server tables so that Access can "see" the structural changes to the tables.
NOTE: You cannot modify the data in the TimeStamp field. SQL Server handles that automatically.

gentle way for inserts to sql server

I want to do inserts in a sql server db with an asp.net core api.
The data I get includes 9 values and 4 of them are connected to other tables. Is it better to simply try the insert via ef core and catch the sql exception if some values are not in the tables or is it better to look for that before (what means more querys in one api request)?
If the data is invalid I only do one insert in another table.
The percentage of invalid data is about 5%.
You should check if the data from the other table already exists or not.
Also, depending on you DB models configuration, you might end up with duplicate items if you try to insert items that exist, without retrieving and updating them.

Microsoft Sync Framework Filters

After first synchronization with filters, data created before first synchronization is not downloaded if matched by filter through new association.
I have one SQL Server and several SQL Server CE clients. I create scopes <MAC>#Setup where filtered data is sent to the clients in a download DirectionOrder. The first synchronization occurs OK (schema is created and data is downloaded), in the subsequent syncs, data created before first synchronization is not downloaded if matched by filter. Only new inserts or updates are considered.
SyncFx tracks and applies changes per table. assuming you have a linking/association table, when you change the association, it's the association table that is updated. SyncFx will not grab the associated rows from the other tables as it only knows that the linking/association table was updated, not the related tables.

timestamp vs date column sql azure for data sync and optimistic concurrency

Using Sql Azure with entity framework. Most of our tables have a date column where we store when the record was edited and by whom. Is there a benefit of making those columns into a timestamp column for the following reasons
Does timestamp help if we want to synchronize this db with another db with SQL Data Sync i.e. if we have a timestamp column that we can use both for our logging and data sync especially if data sync insists on all the tables having a timestamp column
Will having this column help with optimistic concurrency (via entity framework)?
To answer your first question, No. the SQL Data Sync service will create its own change tracking mechanism and you cant configure it to reuse your timestamp column.

Resources