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
  • 32,326
  • 33
  • 105
  • 164
user1151874
  • 269
  • 3
  • 5
  • 15

2 Answers2

9

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,329
  • 12
  • 26
Andomar
  • 232,371
  • 49
  • 380
  • 404
2

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()
supercrash10
  • 73
  • 1
  • 5