Jeremy F.
Jeremy F.

Reputation: 1880

VB.NET Cannot connect to Oracle Server

I receive the error below when running the following function. The catch says the line where it opens the connection (Me.OracleConn.Open()).

I have made sure that the server exists in the TNSNAMES.ora file.

Imports NetOracle = System.Data.OracleClient
...
Private Property OracleConn As NetOracle.OracleConnection
...
    Private Function Connect_To_Oracle() As Boolean
        Connect_To_Oracle = False

        Try

            'Me.OracleConn = New NetOracle.OracleConnection
            Me.OracleConn = New System.Data.OracleClient.OracleConnection
            Me.OracleConn.ConnectionString = "Data Source = (DESCRIPTION=" & _
                      "(ADDRESS_LIST=(ADDRESS = (PROTOCOL = TCP)(HOST = servername.net)(PORT = ####)))" & _
                      "(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME = risk)));" & _
                      "User Id=user_name;Password=password;"

            Me.OracleConn.Open()
            Connect_To_Oracle = True
        Catch ex As Exception
            MsgBox("Oracle Connection Error:" & ex.Message)
        End Try


    End Function

enter image description here

Upvotes: 0

Views: 1476

Answers (2)

Andrei Dvoynos
Andrei Dvoynos

Reputation: 1145

Have you tried using ODP.Net without TNSNames? I find it quite easier than struggling with a txt file on your system...

The connection string would look something like this:

Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=MyHost)(PORT=MyPort)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=MyOracleSID)));User Id=myUsername;Password=myPassword;

It's basically the same information that you put on the TNSNAMES but instead you put the connection info on your web.config.

Upvotes: 0

Related Questions