1
ALTER DATABASE test SET ENABLE_BROKER

this is the sql query i wish to execute while program is executing.. because i do not want to everytime i change computer also need open sql management tool to execute this query rath

MatthewMartin
  • 31,164
  • 31
  • 106
  • 162
user1151874
  • 229
  • 3
  • 4
  • 15

2 Answers2

8

You can fire alter database like a regular SQL statement:

Dim connection As SqlConnection
connection = New SqlConnection("Data Source=myServerAddress;" & _
    "Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;")
Dim command As SqlCommand
command = connection.CreateCommand()
command.CommandText = "ALTER DATABASE test SET ENABLE_BROKER"
command.ExecuteNonQuery()    

 

Andrew Briggs
  • 1,311
  • 11
  • 25
Andomar
  • 225,110
  • 44
  • 364
  • 390
1

Better late than never. Missing opening and closing of the connection. In case anyone needs it:

Dim connection As SqlConnection
connection = New SqlConnection("Data Source=myServerAddress;" & _
    "Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;")
connection.Open()
Dim command As SqlCommand
command = connection.CreateCommand()
command.CommandText = "ALTER DATABASE test SET ENABLE_BROKER"
command.ExecuteNonQuery()
connection.Close()