Peter Mcwell
Peter Mcwell

Reputation: 11

How can I execute this t-sql statements using c#?

I need to execute these t-sql statements using c#, for some reasons I do not want to put them in stored procedure.

SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
GO

BEGIN TRANSACTION

UPDATE mytable
SET col=col 

WAITFOR DELAY '00:02:00'  

ROLLBACK TRANSACTION

Upvotes: 0

Views: 154

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1064324

You cannot execute that as one batch because it is not one batch. You cannot put GO in the middle - that separates batches in editors like SSMS but is not actually T-SQL itself.

Your code, however, does not need that GO - so just remove it. Or execute it as two separate batches on the same connection (which is exactly what tools like SSMS will do with this).

Upvotes: 3

Related Questions