Using SQLCMD script in SMO

  • 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.

  • 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

  • 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.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply