Apologies if this has been asked before. I have searched for an hour and not found the exact problem I am having.
I am using SMO to run some queries against SQL Server, because I have read this can handle GO
statements, as opposed to System.Data.SqlClient
.
I am running this query:
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
UPDATE Program
SET ENABLED = '1'
WHERE Program_ID = '64' AND Program_Name = 'DoesSomething'
I am capturing the "rows affected" by:
int numberOfRows = db.ConnectionContext.ExecuteNonQuery(s.Query);
The problem I am having is that this returns a value of -1 every time. I am checking the database behind the scenes and it DOES update the value every time, and when I manually run the query in SSMS, I receive the (1 row affected) confirmation.
After reading some other posts I have come to think the problem may be in the first four lines of this query. I removed the GO
statements, and the query returned with a value of 1 instead of -1.
Most queries/scripts my group writes has GO
, SET ANSI_NULLS ON
, and SET QUOTED_IDENTIFIER ON
pretty much as standard so its everywhere (another problem for another day- I'm aware it is excessive/irrelevant in this case). Is this affecting my row count somehow? If so can you provide some direction for a workaround or perhaps another route to get this result?
And yes... I am aware ExecuteNonQuery
should return the number of rows affected. I just need to know why it is not returning what I think it should (in this case 1).