cschristian78
Technical User
I am having trouble resetting the connection string to my master server. I have a dialog box that defaults the server and database to local and sa respectively. When the user selects refresh, I populate all the of the attached databases and display them in a combo box. The problem is that when the user types in another server name and the hits refresh again, i get the same results. I added a messagebox to see what the problem was and it appears that the connection string is not pulling the cmbserver.text value. Here is the code below.
thanks
**********Refresh Command**********
Private Sub cmd_refresh_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmd_refresh.Click
MessageBox.Show(cmbServer.Text.ToString)
Call SelectEDM()
End Sub
************Command Action************
Public Sub SelectEDM()
Try
'Open Connection to Server
MasterCon.Open()
'Query the Master Database for all databases attached
Dim daFindEDM As New SqlDataAdapter("SELECT DISTINCT name FROM sysdatabases ORDER BY name", MasterCon)
'Create a dataset and fill with results from query
daFindEDM.Fill(dsEDMsonMaster, "EDMsonMaster")
'Create a view of the results and send it to the combobox
dvEDMsonMaster = dsEDMsonMaster.Tables("EDMsonMaster").DefaultView
'View the dataview
cmb_EDM.DataSource = dvEDMsonMaster
Catch
MessageBox.Show("Error in Connecting to Server. Must have Correct Server, User ID and Password.", "Server Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
cmbServer.Text = "(local)"
txtUserID.Text = "sa"
cmbServer.Focus()
MasterCon.Dispose()
Exit Sub
Finally
MasterCon.Close()
MasterCon.Dispose()
End Try
End Sub
********Connection String**********
' Open the connection to the Master Database
Public MasterCon As New SqlClient.SqlConnection("server= " & frmSeekDB.DefInstance.cmbServer.Text & ";Database = master;User ID= " & frmSeekDB.DefInstance.txtUserID.Text & _
";Password= " & frmSeekDB.DefInstance.txtPassword.Text & "")
thanks
**********Refresh Command**********
Private Sub cmd_refresh_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmd_refresh.Click
MessageBox.Show(cmbServer.Text.ToString)
Call SelectEDM()
End Sub
************Command Action************
Public Sub SelectEDM()
Try
'Open Connection to Server
MasterCon.Open()
'Query the Master Database for all databases attached
Dim daFindEDM As New SqlDataAdapter("SELECT DISTINCT name FROM sysdatabases ORDER BY name", MasterCon)
'Create a dataset and fill with results from query
daFindEDM.Fill(dsEDMsonMaster, "EDMsonMaster")
'Create a view of the results and send it to the combobox
dvEDMsonMaster = dsEDMsonMaster.Tables("EDMsonMaster").DefaultView
'View the dataview
cmb_EDM.DataSource = dvEDMsonMaster
Catch
MessageBox.Show("Error in Connecting to Server. Must have Correct Server, User ID and Password.", "Server Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
cmbServer.Text = "(local)"
txtUserID.Text = "sa"
cmbServer.Focus()
MasterCon.Dispose()
Exit Sub
Finally
MasterCon.Close()
MasterCon.Dispose()
End Try
End Sub
********Connection String**********
' Open the connection to the Master Database
Public MasterCon As New SqlClient.SqlConnection("server= " & frmSeekDB.DefInstance.cmbServer.Text & ";Database = master;User ID= " & frmSeekDB.DefInstance.txtUserID.Text & _
";Password= " & frmSeekDB.DefInstance.txtPassword.Text & "")