I have an ASP.NET application with C# behind. The application gets data from WebServices and then it should execute the below update.
sqlQueryString2 = "
UPDATE CI
SET
platform =@platform ,
wstart = @wstart,
wend = @wend,
model = @model,
productDescription = @productDescription,
scanflag = @scanflag
WHERE serial = @serial ";
I realized that my application seems to be looping when certain values are returned from the Web service. The UPDATE is sent, doesn’t commit, and then it is picked up again on the next loop as needing to be updated.
I did a trace in SQL(Server 2005) and this is what is hitting the server:
exec sp_executesql N'
UPDATE CI
SET
platform =@platform ,
wstart = @wstart,
wend = @wend,
model = @model,
productDescription = @productDescription,
scanflag = @scanflag
WHERE
serial = @serial ',N'
@serial nvarchar(11),
@platform nvarchar(23),
@wstart varchar(10),
@wend nvarchar(10),
@model nvarchar(24),
@productDescription nvarchar(35),
@scanflag nvarchar(1)',
@serial=N'H01170RAHS6',
@platform=N'Client Computer - Apple',
@wstart=N'05/09/2011',
@wend=N'05/09/2012',
@model=N'iMac (20-inch, Mid 2009)',
@productDescription=N'IMAC 20"/2.26/2X1GB/160GB/SD/MSE/KB',
@scanflag=N'Y'
I suspect that the single doublequote in the productDescription might be throwing it, but I have had a bugger of a time trying to strip it out or replace it with (in.).
I think part of my issue on that front is the value stored when it is populated by the WebServices server is escaped as I can see it as “IMAC 20\”/2.26/2X1GB/160GB/SD/MSE/KB” in the watch list.
I have tried replacing the escaped and non escaped quote with String.Replace as well as a RegEx statement.
TBH I’m not even sure I’m on the right track with the quote. I’m only looking at it because not all returns contain one and they don’t all loop.
The double quotes should not be a problem: inside of a string, they are just another character. (They have meaning outside of string constants but that is not what’s going on here.)
I strongly suspect your problem is not a SQL syntax error. If it were, you’d see it show up in multiple places.
For example, you would see them in SQL Profiler (if you included Errors and Exceptions in your trace). You could also run that exact SQL query you just pasted into SSMS and see that it does/does not work. More to the point, you would be getting a SQL exception on the C# side if the query returns an error. If none of those things are happening, then your query would appear to be working.
More likely, the query is running, but not doing anything, so you are picking up the same records over and over as needing updating. Again, running in SSMS will give you the “1 row(s) updated” message that should help you track this problem down.