Connecting VB.Net to Oracle 11GR2 DB
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Connecting VB.Net to Oracle 11GR2 DB

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    PA
    Posts
    122

    Connecting VB.Net to Oracle 11GR2 DB

    I need to connect to an Orace 11GR2 database from a VB.Net Desktop application. I am getting various errors depending on what connection string I use.

    Errors are either ORA 12154: TNS Name cannot be resolved or, Data Provider Internal Error (-3000) (error and string association in code snippet).

    As a reference, I have followed the instructions from:
    http://www.oracle.com/webfolder/tech..._VBVersion.htm

    I have installed the most recent Oracle Client with ODAC, tested the connection with the SQL Developer utility and all seems good.

    Any ideas on what to do next?

    Using Visual Studio 2005 on an XP developers workstation.

    Here is my function for connecting:

    Code:
        Function openOracle() As OracleConnection
            Dim orconn As New OracleConnection
            Dim cnstr As String
            dbfail = False
    
            'tnsnames.ora()
            'ORCL =
            '   (DESCRIPTION =
            '       (ADDRESS_LIST =
            '           (ADDRESS = (PROTOCOL = TCP)(HOST = e9db)(PORT = 1521))
            '       )
            '       (CONNECT_DATA =
            '           (SERVICE_NAME = orcl.domain.local)
            '       )
            '   )
    
            Try
                cnstr = "Data Source=(DESCRIPTION =" & _
                        "   (ADDRESS =  " & _
                        "       (PROTOCOL = TCP)(HOST = e9db)(PORT = 1521)" & _
                        "   )" & _
                        "   (CONNECT_DATA =" & _
                        "       (SERVICE_NAME = orcl.domain.local)" & _
                        "   );" & _
                        "   User Id=un;" & _
                        "   Password=pass" ' <-- ORA 12154
                'cnstr = "Data Source=un/pass@e9db:1521/orcl;" ' <--  ORA 12154
                'cnstr = "Data Source=ORCL;User ID=un;Password=pass" ' <-- Data Provider internal error (-3000)
                orconn.ConnectionString = cnstr
                orconn.Open()
            Catch ex As OracleException
                dbfail = True
                Dim Message As String = "An error occurred while attempting to open the Oracle connection " & vbCrLf & "The error returned is: " & ex.Message.ToString()
                Dim Caption As String = "Error Detected with Oracle Connection"
                Dim Buttons As MessageBoxButtons = MessageBoxButtons.OK
                MessageBox.Show(Message, Caption, Buttons)
                'Me.Close()
            Finally
                'orconn.Dispose()
            End Try
            Return orconn
        End Function
    Last edited by rick7423; September 19th, 2013 at 09:22 AM.
    There are 10 types of people in the world, those that understand binary and those that don't.
    Using VS 2010

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,091

    Re: Connecting VB.Net to Oracle 11GR2 DB

    Don't know if this would help, but have you had a look at the documentation for this error? As in :

    http://ora-12154.ora-code.com/

  3. #3
    Join Date
    Jul 2003
    Location
    PA
    Posts
    122

    Re: Connecting VB.Net to Oracle 11GR2 DB

    It would appear as though the spaces and tabs within the string caused this to fail. When I removed all white space from the TNSNAMES string and put that as the connection string, it works. The final connection string used was:

    Code:
    cnstr = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST= e9db)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=orcl.domain.local)))"
    There are 10 types of people in the world, those that understand binary and those that don't.
    Using VS 2010

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center