Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Using SQLCMD script in SMO Expand / Collapse
Author
Message
Posted Thursday, August 18, 2011 5:30 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, September 08, 2011 12:10 PM
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.
Post #1161673
Posted Thursday, September 08, 2011 12:05 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Sunday, March 23, 2014 8:39 AM
Points: 22, Visits: 82
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
Post #1172052
Posted Thursday, September 08, 2011 12:17 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, September 08, 2011 12:10 PM
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.
Post #1172059
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse