Executing .sql file using in .NET

Hello,

I want to execute .sql files against my database in c#.

please Help me.




Answer this question

Executing .sql file using in .NET

  • Tower Boss

    Jens Thanks for Reply

    I have .sql file generated by SQL Server Enterprise manager.

    i want to execute this file. but it does not.

    Then i have generate .sql file for each object separately.

    now file table.sql (for tables only) runs correctly,

    but for view (view.sql) doesnot run properly.

    in all case error is same

    "Create view must be first line in Query Batch."

    Now what to do

    Waiting for Your Reply

    Emersion



  • infoworx

    Or you can split the file .sql file into multiple files at the lines where the "GO" commands were originally.



  • Matthew!!!

    I assume this is the problem you are referring to:

    "Code gives error where GO command is there in script;".

    A SqlCommand string cannot contain the "GO" command. If you remove the lines containing the "GO" commands you should be fine.



  • EJKing89

    Thanks peter for reply

    I have already tried script removeing "GO" but still it is not working.

    actually i have generated script files by system(SQL Sever Enterprise Manager) itself.



  • Muhammad Umer

    Hello, Jens

    Yes i know that you have posted that .

    but i have replied it problem of that code

    bcoz i had written same kind of code.

    http://forums.microsoft.com/MSDN/showpost.aspx postid=323013&siteid=1

    Uday



  • Arunka

    Do you want to execute more than one file in a directory Or what do you want to achieve

    HTH, Jens Suessmeyer.

    ---
    http://www.sqlserver2005.de
    ---

  • bam

    Ok, did you try to serparate the string object you are getting back from reading from the file by splitting it into a string array and executing each string in the string array

    Thats the think which comes up in mind for this problem.

    Jens.


  • spencery2

    Hi,

    funny thing, I posted that this week in the SMO group:

    http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=318250&SiteID=1

    HTH, Jens Suessmeyer.

    ---
    http://www.sqlserver2005.de
    ---

  • Executing .sql file using in .NET