0

My environment uses Laravel framework with a single MSSQL Database is used as the Session and Application database driver. A single database driver (connection) is used by the application.

The web server and the database server are on different virtual machines. Both the server runs on CentOS (Linux variant) operating system.

A master web page has a list or IDs. Clicking an ID opens the 2nd detail web page which makes an AJAX request to a REST API. The REST API invokes an external Web Service that is hosted on a different network. The AJAX call sometimes completes faster and provides the response to the caller function, but in few cases takes more time to complete.

The web page and the REST API are part of the same application and hosted in the same server instance. The application is not load-balanced.

When the user visits the master web page and click the record having ID as 1, the ID session variable is first programmatically assigned a value of 1 and then the AJAX call is made. When the user moves back to the master web page and click the record having ID as 2, the ID session variable is programmatically reassigned a value of 2. When we retrieve the value of the ID session variable, we get 2, as expected.

However, only in the cases when the AJAX call takes more time to complete, even though we programmatically reassigned a value of 2 to the ID session variable, on retrieving it, we in occasions get a value of 2 (expected value) and in other occasions we get a value of 1 (unexpected, previous value).

We are not sure whether the reassignment of the session variable was not committed or rolled back for any reason.

We are also not sure whether it is to do with any specific version of PHP, Laravel, MS SQL Server, etc, which we don’t think so.

Can anyone throw some pointers on why the value after the session reassignment is not the new value, but still the old value?

Arun
  • 1

1 Answers1

0

I think your 'commit' thought is the right line to go down. Try with autocommit switched on from your sql:

SET IMPLICIT_TRANSACTIONS OFF

If it works that way, switch autocommit off again and make sure your code does all the right commits.

This is discussed in detail in this popular SO question: How do you set autocommit in an SQL Server session?

MandyShaw
  • 1,088
  • 3
  • 14
  • 22