Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Using SQLCMD script in SMO


Using SQLCMD script in SMO

Author
Message
apatel903
apatel903
Forum Newbie
Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)

Group: General Forum Members
Points: 6 Visits: 10
Hello,

I have a C# program which uses SMO to submit tsql to SQL Server 2008 R2 for execution. The tsql is read in from a script file and this works fine.

However if I give it a script file which contains some sqlcmd syntax I get an exception saying "Incorrect syntax near ':' .

Is it the case that SMO does not support script files with sqlcmd syntax?

If that is the case, please can anyone you suggest alternatives.

Thank you,
Anil.
SQLALX
SQLALX
Grasshopper
Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)

Group: General Forum Members
Points: 24 Visits: 83
AFAIK, SMO does not support SQLCMD script such as !!, :*, etc.

You might want to create a SQLCMD process in your C# application and pass the SQLCMD script as a input parameter.

SQLALX
http://sqlmgmt.com
http://sqlbeyond.blogspot.com
apatel903
apatel903
Forum Newbie
Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)

Group: General Forum Members
Points: 6 Visits: 10
Many thanks for your reply.

I had considered that option but I was not allowed to use it (there were concerns that SQLCMD might not exist on the client PC).

In the end, I preprocessed the script file by commenting out the SQLCMD syntax and replacing the variables with the assigned values.
That was adequate and worked.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search