No, I don't think you can just specify a file and then execute the sql scripts inside the file. You must open your file and store its content in a string var and pass it in a ExecuteNonQuery. To make it simplier you can do this: command1.ExecuteNonQuery(File.OpenText('C: Test.sql').ReadToEnd); cheers, Paul June A.
SQL developers can run vb script files from SQL Server t-sql codes by using xp_cmdshell procedure.
It is sometimes a requirement especially for web developers to call vb script from SQL Server engine and execute vbscript from sql code.
Sep 28, 2020 In this tech-recipe post, we will review and learn to execute SQL files using SQLCMD. Moreover, saving the output log of executed SQL files for future references. Save the file with a T-SQL statement as a.SQL file. Make sure it contains a GO keyboard at the end of the script file to indicate the end of the batch statement. VBscript to run sql file from MS SQL. More actions December 5, 2017 at 7:02 am #330404. Hi, I am digging arount internet and the solutions are not working for. Oct 13, 2014 The sqlcmd utility lets you run entire SQL script files full of t-sql via command prompt. Leveraging this tool, you can create a batch file to run the sql script files in sequence. How To Execute A SQL Script File Via Command Prompt With SQLCMD. Although there are TONS of command line options for executing a sql script. Just executing a sql. Using the command line we can run or execute any SQL scripts file with SQL Server Management Studio(SSMS) step to step Step 1: Please below my Example, copy the following code and and paste into the notepad it as save Product.sql file under the C: SQLScripts folder.
Of course calling vbscript from sql can be solved by using CLR in SQL Server after the release of SQL Server 2005.
T-SQL developers and SQL Server database administrators can develop CLR objects and CLR procedures and use .NET Framework objects and methods instead of using sql VBScript.
I hope you will learn SQL Server sql vbscript call methods as many database professionals do on Microsoft data platform after reading this sql tutorial.
Here is a very simple vbscript example where vb script codes are stored in a text file named 'vb-sample.vbs'.
You can also create this vbscript file by running Notepad.exe and copy-paste the below vbscript code into it. Save and name the vbscript file as vb-sample.vbs in root folder of C drive for example.
The above vbscript code create a text file name vbscript-from-sql-server.txt in root of C drive.
Here is execute VBScript sql query example for tsql developers and SQL Server database administrators can use in their applications.
I can guess how you are astonished when you see how easy it is to call vbscript using sql code in MS SQL Server database.
Using tsql vbscript files can be executed by using the xp_cmdshell stored procedure which can reach Windows server objects as seen in this example.
Vbscript To Run .sql File
When xp_cmdshell extended stored procedure is executed, the following error message might come up.
This error thrown from SQL Server engine is caused related with the SQL Server configuration settings.
On the current installed SQL Server instance, execute xp_cmdshell command might be prevented as a matter of security.
The default SQL Server configuration setting for xp_cmdshell is disabled by default with a value of '0' for run-value.
First set 'show advanced options' configuration settings to 1 on the SQL Server 2008 instance using the below t-sql script.

If 'show advanced options' settings parameter is 0 or disabled, trying to configure 'xp_cmdshell' setting will cause the following error message.
So first enable 'show advanced options', then enable 'xp_cmdshell'
Then you are ready to configure xp_cmdshell configuration settings for SQL Server 2008 database instance using the below sql code.
If you have not yet configured xp_cmdshell, run the below sql batch for configuring related parameters.