Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Could the php mssql_query function be locking tables in the SQL database?

Posted on 2013-11-14
3
Medium Priority
?
452 Views
Last Modified: 2013-11-14
Hi,  I am using the following code to query a remote SQL server with a select statement.  Could this be locking that database?

Thanks for any direction you can give!

$link = @mssql_connect($myServer,$myUser,$myPass);
mssql_select_db($myDB) or die('Couldn\'t load database');
$qry = "Select cast(GUIDProduct as varchar(36)) as myProductGUID, DATALENGTH(ProductPicture) as myImageSize, *
		from Product";
$rs = mssql_query($qry);
$RowCount = mssql_num_rows($rs);
if($RowCount>0){
	while($rows = mssql_fetch_assoc($rs)){
		//do something with recordset
	}
}

Open in new window

0
Comment
Question by:lthames
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 49

Accepted Solution

by:
PortletPaul earned 2000 total points
ID: 39650024
It could, yes.

Typically when a query is executed in mssql that query places a shared lock on the table(s) so other operations requiring an exclusive lock on the table(s) involved would need to wait until the shared lock is released.
If READ_COMMITTED_SNAPSHOT is set to OFF (the default), the Database Engine uses shared locks to prevent other transactions from modifying rows while the current transaction is running a read operation.
http://technet.microsoft.com/en-us/library/ms173763(v=sql.105).aspx

This behaviour can be modified e.g:

turning on the database READ_COMMITTED_SNAPSHOT option
including "with nolock" into the query sql

Note these are NOT the same thing, using "with nolock" can return as yet uncommitted records that subsequently might be rolled back.
0
 

Author Comment

by:lthames
ID: 39650097
Thank you for your quick response.  

This definitely explains what's going on.  They are trying to import products into the database (which in that app requires exclusive lock during the import)  and at the same time my php script is syncing the products to their webstore . . . . . and their internet connection is so slow that a query that normally takes 1-2 seconds is taking 3 minutes!!!!!!!!!!
0
 
LVL 49

Expert Comment

by:PortletPaul
ID: 39650132
& Thanks for the quick grading :)

You will need to discuss this with the client then. If "syncing" I'd assume you only want valid data on the website, so using "with nolock" might be risky given that:
> an import might fail
> you are also being slowed down by connection speed.

They may be willing to use READ_COMMITTED_SNAPSHOT on perhaps?

Good luck with this project.

Paul
0

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

597 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question