Can't open oracle database from using remote pc

johnkosten

New member
Joined
Aug 28, 2005
Messages
2
Programming Experience
1-3
Hello,

I'm currently having poblem accessing an oracle database using a remote pc. I'm trying to access oracle 10g throught .Net. The error is "connection must be open for this operation". Below is the code. Any help would be greatly appreciated.

********************************************************
Dim oradb As String = "Data Source=(DESCRIPTION=" _ +"(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=johan)(PORT=1521)))" _
+ "(CONNECT_DATA=(SERVICE_NAME=test)));" _
+ "User Id=hr;Password=test;"

Dim conn As New OracleConnection(oradb)
Try
conn.Open()

Dim cmd As New OracleCommand
cmd.Connection = conn

cmd.CommandText = "select employee_id, first_name, email from espatial"

cmd.CommandType = CommandType.Text

Dim dr As OracleDataReader = cmd.ExecuteReader()

While dr.Read()
ListBox1.Items.Add(dr.GetString(1) + _
"'s email address is " + dr.GetString(2))
End While
Catch ex As OracleException ' catches only Oracle errors
Select Case ex.Number
Case 1
MessageBox.Show("Error attempting to insert duplicate data.")
Case 12545
MessageBox.Show("The database is unavailable.")
Case Else
MessageBox.Show("Database error: " + ex.Message.ToString())
End Select

Catch ex As Exception ' catches any error
MessageBox.Show(ex.Message.ToString())
Finally
conn.Dispose()
End Try
*****************************************************
 
Back
Top