No internet connection but DB connects!!!

A

Anil Gupte

I have the following class that I am using to manage my database
interactions. I disconnected my PC from the Net (disabled my connection in
Network properties). Interestingly the call to Function SetDBconnect
worked - even though I was not connected to the IP address. However, the
ConnL3Producer.Open() failed with an exception. Any ideas why? Am I doing
something wrong?

By the way, any suggestions on a better way to do what I am doing in this
class are also welcome. Also, I am also lokoing for a clean and simple way
to check if an internet connection exists.

Thanx!

Imports System.Data.OleDb
Public Class DB
Dim ConnStrL3Producer As String
Dim ConnL3Producer As New OleDbConnection
Public Function SetDBConnect()
Try
Catalog=L3;Use Procedure for Prepare=1;Auto
Translate=True;Persist Security Info=True;Provider="SQLOLEDB.1";Workstation
ID=AUM;Use Encryption for Data=False;Packet Size=4096
ConnStrL3Producer = "User ID=xxxx;Tag with column collation when
possible=False;Data Source=" & Chr(34) & "111.111.11.11" & Chr(34) &
";Password=xxxx;"
ConnStrL3Producer = ConnStrL3Producer & "Initial Catalog=L3;Use
Procedure for Prepare=1;Auto Translate=True;Persist Security
Info=True;Provider="
ConnStrL3Producer = ConnStrL3Producer & Chr(34) & "SQLOLEDB.1" &
Chr(34) & ";Workstation ID=AUM;Use Encryption for Data=False;Packet
Size=4096"
ConnL3Producer = New OleDbConnection(ConnStrL3Producer)
Catch ex As Exception
Dim strErrMesg As String
strErrMesg = "Caught this Error: " & ex.ToString() & "
Description: " & ex.Message()
MsgBox(strErrMesg, MsgBoxStyle.OKOnly, "Blimey!")
End Try
'Return ConnL3Producer
End Function
Public Function GetRecords(ByVal strSelect)
Dim cmdInit As OleDbCommand = New OleDbCommand(strSelect)
cmdInit.Connection = ConnL3Producer
If Not ConnL3Producer.State = ConnectionState.Open Then
ConnL3Producer.Open()
End If
Dim OleDbAdapterRec As New OleDbDataAdapter
OleDbAdapterRec.SelectCommand = cmdInit
'Dim DataSetInit As New DataSet
Dim DSet As New DataSet("DataSetInit")
OleDbAdapterRec.Fill(DSet, "Transactions")
Return DSet
End Function
End Class
 
B

Branco Medeiros

Anil said:
I have the following class that I am using to manage my database
interactions. I disconnected my PC from the Net (disabled my connection in
Network properties). Interestingly the call to Function SetDBconnect
worked - even though I was not connected to the IP address. However, the
ConnL3Producer.Open() failed with an exception. Any ideas why? Am I doing
something wrong?
Public Function SetDBConnect()
ConnL3Producer = New OleDbConnection(ConnStrL3Producer)
<snip>

Because it's in the Open method that the actual connection with the DB
will be established.

HTH.

Regards,

Branco.
 

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