running long SQL script in file

I've got a long sql script that I want to run from my VB code. The script is in a file, say somefile.sql. Any suggestions on how best to do this


Answer this question

running long SQL script in file

  • johnmurray

    Open the script file with a stream or file reader, read/parse the file into executable sql statements and execute as a data command object

    HTH



  • MaxWeber

    Or use a stored procedure and/or direct Ado.NET using parameters and hence negate the ability for malicious users to use SQL injection.

    I won't make a suggestion to which is better, in-line SQL vs. sProcs.....that's a touchy subject for database programmers.


  • Nick Savoiu

    Put the SQL Script into a stored procedure.

    Execute the stored procedure.


  • howardtr

    And for heavens sake, do some safety checks! This is a common vulnerability when using SQL.

    Suppose you have a textbox, and allow a user to type in the value for a SELECT command.

    cmdstring = "SELECT * FROM mytable WHERE name =' " & textbox1.text & " ' "

    What do you suppose happens if a malicious user enters:

    TOM JONES ' ; DROP TABLE mytable

    Thats right... say goodbye to your table! Be darned sure to restrict access to your script file, and/or parse any user inputs for unexpected commands.


  • running long SQL script in file