Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 157 Stack Exchange communities.

What is meta?
Here's how it works:
  1. Any Stack Exchange user can ask a question
  2. The community provides support, votes on ideas, and reports bugs
  3. Your voice helps shape the way Stack Exchange operates


-- [Enter Query Title]

Results in:

Error: System.InvalidOperationException: ExecuteReader: CommandText property has not been initialized at System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean async) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) at System.Data.SqlClient.SqlCommand.ExecuteReader() at CloudOverflowWeb.Helpers.QueryRunner.PopulateResults(QueryResults results, SqlCommand command, StringBuilder messages) in C:\Users\sam\Desktop\Source\cloudoverflow\CloudOverflow\CloudOverflowWeb\Helpers\QueryRunner.cs:line 153 at CloudOverflowWeb.Helpers.QueryRunner.ExecuteNonCached(ParsedQuery parsedQuery, Site site, User user) in C:\Users\sam\Desktop\Source\cloudoverflow\CloudOverflow\CloudOverflowWeb\Helpers\QueryRunner.cs:line 91 at CloudOverflowWeb.Helpers.QueryRunner.GetJson(ParsedQuery parsedQuery, Site site, User user) in C:\Users\sam\Desktop\Source\cloudoverflow\CloudOverflow\CloudOverflowWeb\Helpers\QueryRunner.cs:line 236 at CloudOverflowWeb.Controllers.QueryController.Execute(String sql, Int32 siteId, String resultsToText) in C:\Users\sam\Desktop\Source\cloudoverflow\CloudOverflow\CloudOverflowWeb\Controllers\QueryController.cs:line 138

share|improve this question
Also, just to note, GO is not syntax-highlighted blue in the query window. – Jon Seigel Jun 7 '10 at 19:45
The same error still shows up even if you comment out the GO. – Jason Punyon Jun 7 '10 at 19:45
@Jason: Confirmed. In fact, you can put 'go' anywhere in a comment and it will blow up. Try -- Some goon broke Data Explorer. – Jon Seigel Jun 7 '10 at 19:50
.... bahhh oversight by me I'll fix this, go should only be handeled if its the only word in a line and if there are empty batches it should simply ignore. – waffles Jun 7 '10 at 22:39
status-completed – waffles Jun 8 '10 at 11:12
@JonSeigel: Goto considered harmful! – Andrew Grimm Sep 22 '11 at 22:27
up vote 5 down vote accepted

Data Explorer does some pretty rudimentary stuff to support GO separators (which as Joel points out are not in the SQL spec)

Basically if we see a GO by itself in a batch we will treat it as a batch separator. This allows you to do nifty things like set showplan_text on and so forth.

However to fully support the go separator you need a parser, something that is out of scope and would take weeks to build in a robust way.

Waffles, in his infinite wisdom, had a trivial bug in the Regex that looks for Gos, this caused a lot of confusion and has been fixed.

This however will require a fair bit of regex foo to fix:

select 'go' go select 1 as [go]
-- go 
select '/* 
*/' as [100] /* 

We all know that you can not build an html parser using regex.

So to recap, if Go is by its lonesome on a line, it will be treated as batch separator. If any batches happen to be totally empty they will be ignored.

share|improve this answer

Here's what I think is going on. The data explorer is splitting queries using the delimiter go in order to provide the batching for things like showing the query plan. So this works:

select 'Hello World'
select 'Adios World'

While this doesn't...

select 'Hello World'

...because the second query is empty.

A query where go appears in a string literal ends up giving this error because the query is split and the string literal isn't closed with a '.

share|improve this answer
Makes sense; probably some naïve string.Split call in the parsing code. – Aarobot Jun 7 '10 at 20:12
Nice detective work. – mmyers Jun 7 '10 at 20:14
I just tried it, if you do GO at the start of the query (GO SELECT 'a'), it fails as well. – Jon Seigel Jun 7 '10 at 20:16
@mmyers: It doesn't compare to…, but thanks all the same :) – Jason Punyon Jun 7 '10 at 20:19
yerp that would be it :) – waffles Jun 7 '10 at 22:40

GO is not an SQL keyword! It is the query batch separator used by default in Enterprise Manager, SQL Server Management Studio, and by convention in many other products as well, but it's not technically part of the language.

That makes this exception result even more surprising, because I would expect Data Explorer to merely return an a message about invalid syntax like it does with most other errors, and not bomb out completely.

share|improve this answer
Makes it less surprising to me, given the conditions that lead to this error and the specific message that's showing up. It's most likely some misguided sanitization code causing the problem. – Aarobot Jun 7 '10 at 20:09
Yeah, I realize what GO is -- I guess I took a liberty with the question title -- in fact, the keyword itself is configurable through the options in SSMS. Which does make this error pretty interesting... – Jon Seigel Jun 7 '10 at 20:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .