Execute a stored procedure from a batch file

  • Hi,

    I have to execute an SP from .bat file. What I have done is, I have created a .bat file with the following entry:

    %OpMode% %msISQL% Some_File.sql

    The "Some_File.sql" file contains the following execute statement:

    execute [dbo].[Stored_Proc_Name] 1,0,0,''

    The connection parameters for the database are in another .bat file.

    When I execute the .bat file, am getting the following error:

    Msg 170, Level 15, State 1, Server SERVER_NAME, Line 1

    Line 1: Incorrect syntax near 'ÿ'.

    Any help is appreciated..

    Thanks,

    Nivetha

  • I would suspect that the line you're executing isn't correct.

    Try putting an "echo %OpMode% %msISQL% Some_File.sql" to ensure that it's being called properly (you may need a "pause" in there also).

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
    Links:
    For better assistance in answering your questions
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2

  • Hi,

    Am getting the following entry in my log file when i put echo before

    %OpMode% %msISQL% Some_File.sql:

    CALL C:\sql\core\MS_ISQL_Driver.bat Some_File.sql

    executing MS_ISQL_Driver.bat with input file Some_File.sql

    ---- START ERROR HANDLING -----

    BATCH TERMINATED by unexpected error "in SQL Script Some_File.sql". Skipping remaining batch.

    I think there is problem with the Some_File.sql, means, my way of executing the stored procedure might be wrong..

    I have entry as:

    execute [dbo].[Stored_Procedure_Name] 1,0,0,''

    Is this right?

  • I have the same error message. I am running a batch file that calls a SQL file that runs a pretty simple update script. When I run the script manually, it runs fine. The same syntax that applies to the call to this script is used to call multiple other scripts on a nightly basis, and the others all work. Here is the error message (which I know is not very helpful by itself):

    Incorrect syntax near 'ÿ'.

    Like I said, the same batch file contains calls to 6 SQL scripts, all with the same credentials and syntax.

  • Are you actually getting the lowercase y with the two little dots over it?

    If so, your sql file is saved in Unicode, not standard ASCII. Open the sql file in SSMS, click file ~ save as, and then on the Save button click the little down-arrow at the right - select "save with encoding" and then select 1252 and then you can save it in ASCII.

Viewing 5 posts - 1 through 4 (of 4 total)

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