user1151874
user1151874

Reputation: 279

is that possible to execute sql query on vb.net?

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

Upvotes: 1

Views: 22719

Answers (2)

supercrash10
supercrash10

Reputation: 73

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()

Upvotes: 2

Andomar
Andomar

Reputation: 238076

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()    

 

Upvotes: 9

Related Questions