Building a generic page "Query Analyzer" like in Asp.net with SMO

Posted by Rodrigo on Stack Overflow See other posts from Stack Overflow or by Rodrigo
Published on 2010-03-26T21:59:40Z Indexed on 2010/03/26 22:03 UTC
Read the original article Hit count: 715

Filed under:
|

Hello,

I'm build a web page in ASP.net is supposed to work just like Query Analyzer. It has basically a textarea to input the sql command, and an Execute button.

I'm using SMO to execute the command in the database, as follows:

//Create object  SMO
Microsoft.SqlServer.Management.Smo.Server server = new Microsoft.SqlServer.Management.Smo.Server(new Microsoft.SqlServer.Management.Common.ServerConnection(oConn));

//To execute the command
server.ConnectionContext.ExecuteNonQuery(tbx_cmd.Text);
//OR
myDataset = server.ConnectionContext.ExecuteWithResults(tbx_cmd.Text);

The problem is that the textarea command can contain anything, from a stored procedure (with GO's statements) and any select command that return resultsets, just like Query Analyzer.

But, if I have GO statements, I only can perform the query using ExecuteNonQuery method. If I use the ExecuteWithResults method, it raises errors because of the GO statements.

And if I want the resultsets to be available, of course I can only use the ExecuteWithResults method.

Does anybody knows how can I do to execute the same command texts at the same time?

Thank you!

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about smo