Microsoft Developer Network > Página principal de foros > Visual Basic General > Connecting to Local 10g Oracle DB with VB.Net
Formular una preguntaFormular una pregunta
 

RespondidaConnecting to Local 10g Oracle DB with VB.Net

  • martes, 03 de noviembre de 2009 22:23VBDevNewbie Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     Tiene código
    Hi

    I am trying to connect a simple VB program (Form, button and label) to my local oracle 10g XE and keep getting errors. The most recent errors is the TNS listener

    "Oracle.DataAccess.Client.OracleException ORA-12154: TNS:could not resolve the connect identifier specified "

    Here is what I have done:

    Went to control panel > odbc and created a connection to 10g XE and called it:

    oraconn (this was from other tutorial so it is not used in code but still resides)

    Copied tutorial about connecting to oracle and have the following code:

    Imports System.Data
    Imports Oracle.DataAccess.Client
    Imports Oracle.DataAccess.Types
    
    Public Class Form1
    
        
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim oradb As String = "Data Source=orcl;User ID=hr;Password=hr;"
            Dim conn As New OracleConnection(oradb)
            conn.Open()
            Dim cmd As New OracleCommand
            cmd.Connection = conn
            cmd.CommandText = "select department_name from departments  where department_id = 10"
            cmd.CommandType = CommandType.Text
            Dim dr As OracleDataReader = cmd.ExecuteReader
            dr.Read()
            Label1.Text = dr.Item("department_name")
            conn.Dispose()
        End Sub
    End Class
    I work on VB6 but using VB.NET seems quite a different experience. Everywhere I look someone has done this different and I just want to know how to connect locally and run a simple query then I can build on my VB.NET knowledge. I'm not that sure what I need to do, i've just been experimenting so far and really need help starting this.

    The most urgent requirement is trying to find a logical step by step instruction on how to do this. Every example is different or goes off on tangents, or does not explain as much as I need to know to do the connection to Oracle.

    Any takers?

    Thanks

    Andrew

    P.S. I have already asked this question on vbforums with no success.



    Andrew (MCDST)

Respuestas

Todas las respuestas