Question Run .sql script from executable

scottsanpedro

Member
Joined
Jan 24, 2009
Messages
21
Programming Experience
1-3
Hi all. I hope you will be able to help me out.
I have a system running off a SQLExpress database on a clickonce type application.
As well as updating the application I want to be able to check a version number on the DB and then run a .sql script for updating Stored Procedures or anything really.
Is there a way to add a .sql script or maybe just a .txt file which could then be read and executed via ExecuteStoreCommand.
If I put a .txt into a folder called Scripts, how do I feed that into the ExecuteStoreCommand command?
Thanks in advance
Scott
 
You should be able to read your command into a string variable and then execute using that string:

VB.NET:
Dim cmdText As String = IO.File.ReadAllText("scripts\script1.sql")
 
Last edited:
that will work fine. Thank you.
When I put
VB.NET:
Dim cmdText As String = IO.File.ReadAllText("\Scripts\Version.sql")
I get error Could not find path 'C:\Scripts\Version.sql'.
I presume I will need to link to solution explorer path not my hard drive path of c:?
I will look now how to do this if in fact I can.
Thanks again Scott
 
Back
Top