Smo and SQLCMD commands

  • Thread starter Thread starter Fred
  • Start date Start date
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.
 
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/
 
"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.
 
Back
Top