如何在VB.NET中打开两个连接字符串

时间:2013-10-04 12:37:30

标签: vb.net stored-procedures console-application

我在VB.NET中开发了应用程序。现在我需要为该应用程序实现新功能。

所以我创建了处理新功能的方法。我需要在此方法中调用三个存储过程,其中一个SP来自一个数据库,另外两个SP来自不同的数据库。

现在我可以通过调用一个连接字符串来调用SP。但我不知道如何打开两个连接字符串并调用存在于不同数据库中的SP。

我的代码中有这样的条件:

 If application("skipCharge") Is Nothing Then
 Console.WriteLine("App charges")
 chargeApplication(cxnmarketDb, ConnectionStrings("Applications_" & siteName).ConnectionString, dtAppStart)
 Console.WriteLine()
  End If

此处应用_ 是我的连接字符串名称。我在想的是我需要将第二个数据库连接字符串放在if语句中。但如果我把它放进去,不知道如何选择两者。

这是我方法中的代码:

 Private Sub chargeApplication(ByRef cxnmarketDb As SqlConnection, ByVal cxnApplicationPlaceString As String, ByVal dtAppStart As Date)

        Const chargeEventText As String = "This is a text "
        Using cxnPlace As SqlConnection = New SqlConnection(cxnApplicationPlaceString)
            Try
                cxnPlace.Open()
            Catch exDetail As SqlException
                Console.WriteLine(" +  cxnPlace.SqlException :: " & exDetail.Message)
            Catch exDetail As Exception
                Console.WriteLine(" +  cxnPlace.Exception :: " & exDetail.Message)
            End Try

            If cxnPlace.State = ConnectionState.Open Then

                Using cmdAppList As SqlCommand = cxnPlace.CreateCommand()
                 cmdAppList.CommandType = CommandType.StoredProcedure
                 cmdAppList.CommandText = "First_SP"
                 cmdAppList.CommandTimeout = 60


                 Try
                  Using sdrAppCharge As SqlDataReader = cmdAppList.ExecuteReader()
                  Do While sdrAppCharge.Read()
                  Using cmdChargeSearch As SqlCommand = cxnmarketDb.CreateCommand()
                    cmdChargeSearch.CommandType = CommandType.StoredProcedure
                    cmdChargeSearch.CommandText = "second_SP"
                    cmdChargeSearch.CommandTimeout = 60

我可以在这里拨打first_SP。但在那之后它将转向END声明。因为second_SP在不同的连接字符串中而且没有打开。

那么如何在这里打开两个连接字符串并调用我的存储过程?

0 个答案:

没有答案