Note that there are some explanatory texts on larger screens.

plurals
  1. POconcurrent .net web api service calls returning duplicate data
    primarykey
    data
    text
    <p><strong>The setup</strong></p> <p>We have a web app hosted on IIS 7.5 that uses a .net web api rest service to short-poll a SQL Server 2008 database. The service controller calls a stored procedure to read the data.</p> <p><strong>The problem</strong></p> <p>When concurrent requests are made to the same web service, we intermittently see the duplicate results, and sometime other processes results, returned to the browser.</p> <p><strong>C# service code</strong></p> <pre><code>namespace ImageApp_REST_Services.Repositories { public class ImageLinkRepository : IImageLinkRepository { private List&lt;ImageLink&gt; ImageLinks { get; set; } public IEnumerable&lt;ImageLink&gt; Get(String userId) { ImageLinks = new List&lt;ImageLink&gt;(); using (var cnnSQL = new SqlConnection(...)) { // opend connection to DB cnnSQL.Open(); try { SqlCommand cmmSQL = new SqlCommand("nVision_select_lcimagelinks_sp", cnnSQL); cmmSQL.CommandType = System.Data.CommandType.StoredProcedure; SqlParameter prmSQL = cmmSQL.Parameters.Add(new SqlParameter { ParameterName = "@LCIMGLINKUSERID", Value = userId }); SqlDataReader rdrSQL = cmmSQL.ExecuteReader(); if (rdrSQL.HasRows) { while (rdrSQL.Read()) { ImageLinks.Add(new ImageLink { // set new ImageLink object's properties imageTopicId = DBReader.SQLString(rdrSQL, "LCIMGLINKIMGTOPICID"), id = DBReader.SQLInt(rdrSQL, "LCIMGLINKPK"), recordId = DBReader.SQLString(rdrSQL, "LCIMGLINKRECORDID"), text = DBReader.SQLString(rdrSQL, "LCIMGLINKTEXT"), topicId = DBReader.SQLString(rdrSQL, "LCIMGLINKTOPICID"), topicItem = DBReader.SQLString(rdrSQL, "LCIMGLINKTOPICITEM"), url = DBReader.SQLString(rdrSQL, "LCIMGLINKURL"), user = DBReader.SQLString(rdrSQL, "LCIMGLINKUSERID") }); } } } catch (Exception) { } } return ImageLinks; } } </code></pre> <p>}</p> <p>Again, when multiple requests are hitting the service simultaneously, we occasionally see either duplicate records returned, or records belonging to another service call. </p> <p>We want the service to only return the data for the given request. Does anyone know what is wrong???</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload