I am trying to make a program so I can run batch SQL scripts without installing SSMS.
I have made a basic program which works for single queries.
If MsgBox("Are you sure you want to execute this code?", MsgBoxStyle.YesNoCancel, "Are you sure?") = MsgBoxResult.Yes Then
Dim cmd As New SqlClient.SqlCommand()
Dim connetionString As String
Dim conn As SqlConnection
Dim sql As String
connetionString = "Data Source=Localhost\database;Initial Catalog=master;Integrated Security=True"
conn = New SqlConnection(connetionString)
sql = RTB_Sql.Text
Try
conn.Open()
cmd.CommandText = sql
cmd.Connection = conn
cmd.ExecuteNonQuery() 'execute query
'AddHandler conn.InfoMessage, New SqlInfoMessageEventHandler(AddressOf OnInfoMessage)
Catch sqlEx As SqlException
MsgBox(sqlEx.Message)
conn.Close()
Catch ex As Exception
MsgBox(ex.Message)
Finally
conn.Close()
End Try
Else
End If
rtb_sql.text is a textbox with the users SQL
I would like this program to run batch statements using Variables, Joins, Updates and If statements however it doesn't cope well with it, and eventually errors.
The codes are sound in SSMS, but not in this program. Is it possible to declare the sql as something else maybe?
Thanks
Can anyone suggest a solution?
Thanks!