SMO Disconnect

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can I disconnect from the selected server and connect to another server
during runtime,

I'm always receive the following error message
Connection properties cannot be changed after a connection has been
established.

This is vb code I'm using

Private Sub testCONNECTION()



lstDatabases.Items.Clear()


With svr.ConnectionContext
.AutoDisconnectMode = AutoDisconnectMode.NoAutoDisconnect
.Disconnect()

Try
DBGEGEVENS.server = lstServers.SelectedItem.ToString 'svr.Name

If chkWinSecure.Checked = False Then

DBGEGEVENS.WinSecurity = False
.LoginSecure = False
.Password = txtPas.Text
.Login = txtUser.Text
.Connect()

Else

DBGEGEVENS.WinSecurity = True
.LoginSecure = True
.Connect()
End If

For Each db As Database In svr.Databases

If db.IsSystemObject = False Then
lstDatabases.Items.Add(db.Name)
End If
Next
ToolStripStatusLabel1.Text = "Connected........"


Catch ex As Exception
MsgBox(ex.Message)
ToolStripStatusLabel1.Text = ex.Message
SchrijfERROR(ex.Message & " testCONNECTION")
.AutoDisconnectMode = AutoDisconnectMode.NoAutoDisconnect
.Disconnect()
End Try

End With
End Sub
 
Back
Top