Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / Database Access / October 2005



Tip: Looking for answers? Try searching our database.

cycling through multiple SQL server connections

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
LP - 28 Oct 2005 19:30 GMT
Hello all,

I am collecting data from multiple servers and dynamically setting the data
source by passing a new IP address.  The first one connects fine but when teh
second connection is opend I get a "Object reference not set to an instance
of an object."

I've taken the steps to create a new connection at the beginning of eah call
to teh procedure and close the connection at the end.  Each time though I run
the first one fine but the second time through it fails.  
Any thoughts?

Thanks
William (Bill) Vaughn - 28 Oct 2005 20:12 GMT
Let's see some code.

Signature

____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com/blog/billva
www.betav.com
www.sqlreportingservices.net
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________

> Hello all,
>
[quoted text clipped - 14 lines]
>
> Thanks
LP - 28 Oct 2005 21:10 GMT
Thanks for getting back with me.

Here goes:

Imports System.Data.SqlClient
Imports System.ServiceProcess

Public Class BaseDataCollector
#Region " Private Member variables "
   Dim AppSettings As New System.Configuration.AppSettingsReader
   Friend WithEvents connRemoteServer As System.Data.SqlClient.SqlConnection
   Friend WithEvents connCentralServer As New
System.Data.SqlClient.SqlConnection
   Dim EL As System.Diagnostics.EventLog

#End Region
   
   Public Sub CollectServerAddresses()
       Try
           Dim i As Integer = 0
           Dim a_IPAddresses(i) As String
           Dim drIPAddresses As SqlDataReader
           Dim cmdIPAddress As SqlCommand

           ' If there are no IP addresses available in the cache then
retrieve them from LW_CP_Servers
           ' If a_IPAddresses.Length = -1 Then
           connCentralServer.ConnectionString = "Persist Security
Info=True;Initial Catalog=MonServer;Data Source=192.168.4.101;Packet
Size=4096;Connection Timeout=120; user id = Cockpit_development; password =
P@ssw0rd;"
           Console.WriteLine(connCentralServer.ConnectionString)
           connCentralServer.Open()
           cmdIPAddress = New SqlCommand("Select Server_URL from
SERVERS_LIST", connCentralServer)
           drIPAddresses = cmdIPAddress.ExecuteReader

           Do While drIPAddresses.Read()
               a_IPAddresses(i) = (drIPAddresses.GetString(0).ToString())
               Console.WriteLine(a_IPAddresses.GetValue(i))
               'Console.WriteLine(i)
               'Console.WriteLine(drIPAddresses.GetString(0).ToString())
               i = i + 1
               ReDim Preserve a_IPAddresses(i)
           Loop

           drIPAddresses.Close()
           connCentralServer.Close()
           'End If

           For i = 0 To a_IPAddresses.Length - 1
               ' Collect all monitored bases
               CollectRemoteServerData(a_IPAddresses(i))
           Next
       Catch ex As Exception
           Console.WriteLine(ex.Message)
       End Try

   End Sub

   Public Sub CollectRemoteServerData(ByVal s_IP As String)
       Try

           Dim RetrievedDatapts As New DataSet
           connRemoteServer = New SqlClient.SqlConnection
           connRemoteServer.ConnectionString = "Persist Security
Info=True;Initial Catalog=remData ;Packet Size=4096;Connection
Timeout=120;Integrated Security=SSPI;Data Source=" + s_IP + ";"
           Console.WriteLine(connRemoteServer.ConnectionString)
           Console.WriteLine(connRemoteServer.State)
           Console.WriteLine(connRemoteServer.DataSource)
           'Console.WriteLine(connRemoteServer.ServerVersion)
           Console.WriteLine(connRemoteServer.Site)
           Console.WriteLine(connRemoteServer.ToString)
           connRemoteServer.Open()

           'SqlHelper.ExecuteNonQuery(connRemoteServer.ConnectionString,
CommandType.StoredProcedure, "datapts_prep_for_transmission")

           ' RetrievedDatapts =
SqlHelper.ExecuteDataset(connRemoteServer.ConnectionString,
CommandType.StoredProcedure, "DATAPT_LISTS_SEL")
           ' EL.WriteEntry("Successful Update")
           'connRemoteServer.ConnectionString = ""
           connRemoteServer.Close()
           connRemoteServer = Nothing
       Catch e As Exception
           EL.WriteEntry("Update Failed" + vbCrLf + e.Message)

       End Try

   End Sub

End Class

> Let's see some code.
>
[quoted text clipped - 16 lines]
> >
> > Thanks
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.