Question How do I close an open Oracle Connection

Mr_MaGoo

New member
Joined
Feb 16, 2012
Messages
2
Programming Experience
Beginner
Hi All,

Very new to this VB.Net lark but picking it up due to extensive knowledge of VBA in Excel & Access :)

I am creating an application that querys a specific table on an Oracle Database.

I can connect to the Database and query it no problem,

However I am unable to close the connection from within the form via my "CloseConnection" button

Here's how i open it:

VB.NET:
Sub ConnectToServer()
        Dim DSN As String = Replace(Me.CBConnection.Text,".WORLD","")
        Dim UID As String = Me.TxtUsername.Text
        Dim PWD As String = Me.TxtPassword.Text
        Dim Cnx As OdbcConnection
        Dim CnxStr As String
                
        CnxStr = "DSN=" & DSN & ";UID=" & UID &" ;Pwd=" & PWD & ";"
                
        Cnx = New OdbcConnection(CnxStr)
        Cnx.Open()
        
        
        'Enable BtnDisconnect
        Me.BtnDisconnect.Enabled = True
        Me.BtnConnect.Enabled = False
    End Sub

So how do i close that specific connection? it does close if i close the form but i don't want that to be the way its done?

Hope you can help :)

Cheers
 
Hi there,

Thanks for your answer however its not what I'm after (Due to me asking the question wrong, so sorry).

Basically, I'm looking to open a connection in the routine I've supplied, then close that connection in a separate routine.

Is that possible, if so how?

Cheers
 
You declared the Cnx variable inside your method, so it ceases to exist whtn the method exits. Make it a variable at the class level instead.

Use System.Data.OracleClient or Oracle.DataAccess.Client instead of odbc
 
Back
Top