I am trying to execute an entire file of SQL commands on SQL Server from a vb.net app. The issue is that if the SQL file contains any CREATE PROCEDURE
commands, I get the following error:
A critical error has occurred. 'CREATE/ALTER PROCEDURE' must be the first statement in a query batch. Incorrect syntax near the keyword 'PROC'
Dim sql = sqlFile.ReadToEnd()
Using conn As New SqlConnection(ConfigurationManager.ConnectionStrings("SiteSqlServer").ToString), cmd As New SqlCommand
With cmd
.Connection = conn
.CommandType = CommandType.Text
.CommandText = sql
.CommandTimeout = 300
End With
conn.Open()
cmd.ExecuteNonQuery
conn.Close()
How can I execute sql files over a SqlConnection
containing CREATE PROCEDURE
commands?