I'm super puzzled by this issue. I've looked up previous posts of 'incorrect syntax' but they had clear examples. I've got some C# code writing DbContext query code to my DB. I've got changing errors pointing at different characters in the same query code:
db.Database.ExecuteSqlCommand("INSERT INTO AspNetUsers (Id, Email,
EmailConfirmed, PasswordHash, SecurityStamp, UserName, Location, First_Name,
Last_Name, Bio, Online_Collaboration, Instrument, Genre, PhoneNumberConfirmed,
TwoFactorEnabled, LockoutEnabled, AccessFailedCount) " +
"VALUES ('" + muser.Id + "', '" + muser.EmailAddress + "', 1, '" +
muser.SecurityStamp + "', '" + muser.Username + "', '" + muser.Location + "',
'" + muser.FirstName + "', '" + muser.LastName + "', '" + muser.Bio + "', 1,
0, 0, 0, 0, 0, 0)");
The errors range. These are some samples below but that 'syntax near x' changes between mainly these letters:
System.Data.SqlClient.SqlException: 'Incorrect syntax near 't'.'
System.Data.SqlClient.SqlException: 'Incorrect syntax near 'll'.
Unclosed quotation mark after the character string '', 1, 0, 0, 0, 0, 0, 0)'
System.Data.SqlClient.SqlException: 'Incorrect syntax near 'm'.
Unclosed quotation mark after the character string '', 1, 0, 0, 0, 0, 0, 0)'
System.Data.SqlClient.SqlException: 'Incorrect syntax near 's'.
Unclosed quotation mark after the character string '', 1, 0, 0, 0, 0, 0, 0)'
System.Data.SqlClient.SqlException: 'Incorrect syntax near 'm'.
Incorrect syntax near the keyword 'with'. If this statement is a common
table expression, an xmlnamespaces clause or a change tracking context
clause, the previous statement must be terminated with a semicolon.'
System.Data.SqlClient.SqlException: 'Incorrect syntax near 'll'.
Incorrect syntax near the keyword 'with'. If this statement is a common
table expression, an xmlnamespaces clause or a change tracking context
clause, the previous statement must be terminated with a semicolon.
Unclosed quotation mark after the character string '', 1, 0, 0, 0, 0, 0,
0)'.'
What I've noticed so far:
- Characters mainly s, t, m and also ll. The 'll' means it can't just be a single character issue. The characters are used frequently throughout the code so it's impossible to pinpoint although I'd imagine they're the symptom, not the cause.
- The 'Incorrect syntax near x' is the only consistent error. I believe the others are just follow-ons. Of the dozens of times I've ran it, it's more the minimal message.
- And finally the most frustrating part - it WORKS (very) infrequently so the syntax should be fine as far as I can see. Maybe it's shitting itself at the processioning end and some timings overlapping? There's a bit of string breaking for variables but I would imagine that's pretty standard load.