Microsoft Developer Network >
Página principal de foros
>
Visual Basic General
>
Connecting to Local 10g Oracle DB with VB.Net
Connecting to Local 10g Oracle DB with VB.Net
- 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 ClassI 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
- Can you connect with SQL Plus or another Oracle utility? If not it sounds like a configuration issue and you may want to post your question to the Oracle Express forum:
http://forums.oracle.com/forums/forum.jspa?forumID=251
Paul ~~~~ Microsoft MVP (Visual Basic)- Marcado como respuestaMartin Xie - MSFTMSFT, Moderadormartes, 10 de noviembre de 2009 6:02
Todas las respuestas
- Can you connect with SQL Plus or another Oracle utility? If not it sounds like a configuration issue and you may want to post your question to the Oracle Express forum:
http://forums.oracle.com/forums/forum.jspa?forumID=251
Paul ~~~~ Microsoft MVP (Visual Basic)- Marcado como respuestaMartin Xie - MSFTMSFT, Moderadormartes, 10 de noviembre de 2009 6:02
- Hi
Had a look at that and wasn't sure which one too choose?
Providers to use when connecting to Oracle» Oracle Data Provider for .NET / ODP.NET (OracleConnection)
» .NET Framework Data Provider for Oracle (OracleConnection)
» dotConnect for Oracle (OracleConnection)
» Microsoft OLE DB Provider for Oracle
» Oracle Provider for OLE DB
» .NET Framework Data Provider for OLE DB (OleDbConnection)
» Oracle in OraHome92
» Microsoft ODBC for Oracle
» Microsoft ODBC Driver for Oracle
» Oracle in XEClient
» .NET Framework Data Provider for ODBC (OdbcConnection)
» MSDataShape
Andrew
Andrew (MCDST) - "Can you connect with SQL Plus or another Oracle utility? If not it sounds like a configuration issue and you may want to post your question to the Oracle Express forum:"
Yes I can connect fine.
Will have a look at the oracle forum thanks
Andrew
Andrew (MCDST) - Below is some more info concerning the message:
http://ora-12154.ora-code.com/
Paul ~~~~ Microsoft MVP (Visual Basic)

