Problems Using Two Connection Objects in Same Program

J

John Altland

Hello,

I need to access two databases on two seperate servers in
one program. One, dblocal, and another, dbserver. Once I
am done the queries on the local database, I dispose the
connection to dblocal and attempt to connect, using a
seperate connection. Once I attempt to open this second
connection, an exception is thrown. I used the connection
string built by the server explorer for both databases so
the problem should not be there, however the
datasource.tostring method returns a null string. I have
looked all over msdn and a variety of webpages and MS
ADO.Net book to find and answer. Can anyone help me out
using to connections at different times in ADO.Net.
 
J

John Altland

Here is my code
Class 1
Dim strDescription As String 'str holding
desription of slide/doc
Dim strFinal As String 'holds formated
final string
Dim TF As New LSI()
Dim SL As New ApplyToStopList(cnn)
Dim MyQueue As New System.Collections.Queue()

'create description of slide/doc for reference
strDescription = MakeDescription(strData)

'prepare data for database entry
strFinal = SL.FormatFromStopList(TF.FormatForLSI(strData))
MsgBox(strFinal)

'make list of words in string and find hits
WordsInString(strFinal)

'get list of words in string
rdr = GetWords()

While (rdr.Read())
MyQueue.Enqueue(rdr(0))
MyQueue.Enqueue(rdr(1))
End While

rdr.Close()
Empty()

cnn.Dispose()

Dim DBA As New Class2()

Dim i As Integer = 0
Dim count As Integer = MyQueue.Count
While i < count
DBA.Add(MyQueue.Dequeue().ToString, path, author,
MyQueue.Dequeue().ToString, sn, strDescription, type)

i += 2
End While
DBA.Clear()
End Sub
End Class1

Class2
Private conn As System.Data.OleDb.OleDbConnection
Private cmd As System.Data.OleDb.OleDbCommand
Private rdr As System.Data.OleDb.OleDbDataReader

Public Sub New()
Me.conn = New System.Data.OleDb.OleDbConnection()
Me.conn.ConnectionString = "connectionstring"
Me.cmd = New System.Data.OleDb.OleDbCommand()
Me.cmd.Connection = Me.conn
MsgBox(conn.DataSource.ToString)
End Sub

Public Sub Add(ByVal strName As String, _
ByRef strPath As String, ByVal strAuthor As String, _
ByVal strHits As String, ByVal strSN As String, _
ByRef strDescription As String, ByVal strType As String)

'if strName is a Keyword in data
If Not (RemoveWhiteSpace(strName) = Nothing) Then
If Exists(strName) Then
'then just insert it into that table
Insert(strName, strPath, strAuthor, strHits, strSN,
strDescription, strType)
Else
'otherwise add it to the keywords and create a table for
it
AddKeyWord(strName)
AddTable(strName, strPath, strAuthor, strHits, strSN,
strDescription, strType)
End If
End If
Private Function Exists(ByVal str As String)
'connects to save pooled connection

'claims is null
MsgBox(conn.DataSource.ToString)

If Me.conn.State = ConnectionState.Closed Then
Me.conn.Open() 'faults here
End If

cmd.CommandText = "SELECT Keywords FROM keywords WHERE Keywords
= '" & str & "'"
rdr = cmd.ExecuteReader
If rdr.Read() Then
rdr.Close()
Return True
Else
rdr.Close()
Return False
End If
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top