Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

VB.NET Connection to Oracle

608596Nov 4 2009 — edited May 22 2010
Hi

Not sure if this is the right place to put this question but here goes.

I have 10g XE om my laptop and Visual Studio.NET 2005.

What I am trying to do is simply connect to the DB and display some records from it on a form, that is it just now.

I have failed to find the necessary logical steps I need to take to create a successful connection to the DB from VB.NET.

In spite of that I have looked at some tutorials that seemed simple enough to implement, however I have an oracle error popping up when I run the program.

I have a simple form with a button and a label to show records. When I press the button the connection should be made but I get this error in VB immediate window:

1) A first chance exception of type 'Oracle.DataAccess.Client.OracleException' occurred in Oracle.DataAccess.dll

And in VB debugging mode I pick up this error:

2) ORA-12154: TNS:could not resolve the connect identifier specified

The code is this:

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
Try
Dim oradb As String = "Data Source=orcl;User ID=hr;Password=hr;"
Dim conn As New OracleConnection(oradb)
conn.Open() *<<<<< Error number 2 pops up here*
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()
Catch ex As Exception
End Try
End Sub
End Class



I'm just not sure if this piece of code is sufficient or there is something else I need to be setting on my own pc.

Is there anyone that can help?

Thanks

Andrew

Edited by: user605593 on Nov 4, 2009 2:16 PM

Edited by: user605593 on Nov 4, 2009 2:17 PM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 19 2010
Added on Nov 4 2009
1 comment
3,677 views