Smo and SQLCMD commands

F

Fred

Hello,

I want to run a script with the ExecuteNonQuery method of a
Microsoft.SqlServer.Management.Common.ServerConnection instance
It seems that this method doesn't accept the SQLCMD commands like
:SetVar

How can I run this kind of scripts from within a .NET program ?

Thanks for your suggestions.
 
D

Dan Guzman

How can I run this kind of scripts from within a .NET program ?

AFAIK, SQLCMD variables are only recognized the the SQLCMD and SSMS tools.
If the SQLCMD API feature is important to you, consider submitting a
feedback suggestion at https://connect.microsoft.com/SQLServer/Feedback.

If all you need is simple SQL variable substitution, consider replacing the
variable tokens with the desired values at run time (e.g.
myScript.Replace("$(DatabaseName)", databaseName) before executing the
script. You'll need to remove SQLCMD commands (e.g. lines that start with a
colon) or omit those from the source script entirely.

--
Hope this helps.

Dan Guzman
SQL Server MVP
http://weblogs.sqlteam.com/dang/
 
F

Fred

"Dan Guzman" <[email protected]> a écrit dans le
message de groupe de discussion :
(e-mail address removed)...
AFAIK, SQLCMD variables are only recognized the the SQLCMD and SSMS
tools.
OK,

If the SQLCMD API feature is important to you, consider submitting a
feedback suggestion at
https://connect.microsoft.com/SQLServer/Feedback.

Yes, it could be interesting.
If all you need is simple SQL variable substitution, consider
replacing the variable tokens with the desired values at run time
(e.g. myScript.Replace("$(DatabaseName)", databaseName) before
executing the script. You'll need to remove SQLCMD commands (e.g.
lines that start with a colon) or omit those from the source script
entirely.

That's what I did. My requirements were very simple. Just set a few
variables.

Thank you Dan.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top