Skip to content
Advertisement

SqlCommand ExecuteNonQuery() not committing changes

I have a function in which i pass through some SQL and attempt to execute it against a database.

The function completes fine and a SQL trace shows me that the query is being executed against the database, but when i refresh my select statement, the data has not updated. In this instance, the query is a simple:

No errors are generated in SQL or Visual Studio, but as mentioned, the update is not committed and the data remains the same.

This is my function code below:

I have tried forcing a commit (currently commented out above) but this results in an “‘This SqlTransaction has completed; it is no longer usable.'” error message caught by the exception catcher. I have spent hours scouring google for answers but i am at my wits end now.

Can anyone please help and explain why my ExecuteNonQuery is executing the SQL query but not committing the change??

I am using Visual Studio Community 2017 and SQL Server 2019.

Edit: mCn comes from another function, OpenDatabase(), shown below:

mCn is what i am using as the database connection – aka “My Connection”

Advertisement

Answer

Seems like you had not commited your transaction anywhere,Try commiting after ExecuteNonQuery

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement