Pedro Rainho
Pedro Rainho

Reputation: 4284

Error with SqlCommand and multi-line comments

I'm having a strange error using dotnet SqlCommand.

Basically I'm executing a command text that has a multi-line comment with a GO in there ex:

/*IF OBJECT_ID ( 'dbo.xxx', 'P' ) IS NOT NULL 
DROP PROCEDURE [dbo].[xxx]
GO 
*/

select * from dbo.abc

The error that I got was "Missing end comment mark '*/'"

I was able to narrow down the error and it seems that the problem is related with the GO. If I remove the GO It works.

If I execute this command and watch the executed query in sql profile I get:

/*IF OBJECT_ID ( 'dbo.xxx', 'P' ) IS NOT NULL 
DROP PROCEDURE [dbo].[xxx]

So part of the query wasn't executed... and end comment mark is missing

I've search to see if anyone was having this problem as I've saw this post on msdn with a similar GO problem...

http://social.msdn.microsoft.com/Forums/sqlserver/en-US/7e5ef20d-4b19-4930-9b1f-64304e6987e2/missing-end-comment-mark?forum=sqlreplication

am I the only one with this problem? Is there a workaround?

Upvotes: 0

Views: 563

Answers (1)

Aaron Bertrand
Aaron Bertrand

Reputation: 280262

I fail to see the point, but the problem is the GO. GO is not Transact-SQL, it's a batch separator for tools like SSMS. Try it without the GO (or without a multi-line comment, or any comment, in the first place).

Upvotes: 4

Related Questions