I was trying to set up a simple test to be able to switch between a remote SQL server and a local SQL server. When I run this it gets data from the remote server and if I change the value of useLocalDB to true and run the stored procedure again I still get the data from the remote.
I'm probably just not understanding the connection process?
Code:Imports System.Data.SqlClient Public Class Form1 Dim tblSteps As DataTable = New DataTable Dim StepsBindingSource As New BindingSource Dim useLocalDB As Boolean = False Dim cnPMSQL_Remote = New SqlConnection(My.Settings.SQLConnectionStringRemote) Dim cnPMSQL_Local = New SqlConnection(My.Settings.SQLConnectionStringLocal) Private Sub ExitProgram_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitProgram.Click Me.Close() End Sub Private Sub RunSproc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RunSproc.Click Dim spSteps As SqlCommand If useLocalDB Then spSteps = New SqlCommand("sproc_shop_order_get_recipe1", cnPMSQL_Local) Else spSteps = New SqlCommand("sproc_shop_order_get_recipe1", cnPMSQL_Remote) End If spSteps.Parameters.AddWithValue("@int_shop_order", "152837000001") spSteps.Parameters.AddWithValue("@int_prev_so", "459761000001") spSteps.CommandType = CommandType.StoredProcedure spSteps.CommandTimeout = 15 tblSteps.Clear() Try Dim StepsAdapter As SqlDataAdapter = New SqlDataAdapter(spSteps) StepsAdapter.Fill(tblSteps) StepsBindingSource.DataSource = tblSteps dgSteps.DataSource = StepsBindingSource Catch ex As Exception Trace.WriteLine(Date.Now.ToLongTimeString & "*: Database not available" & ex.Message) MessageBox.Show("Database not available" & Environment.NewLine & ex.Message & Environment.NewLine & ex.StackTrace) End Try End Sub Private Sub RemoteDB_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RemoteDB.CheckedChanged If RemoteDB.Checked Then useLocalDB = False Else useLocalDB = True End If End Sub End Class




Reply With Quote