Chidi Okeh
Chidi Okeh

Reputation: 1557

Any ideas how to fix "A network-related or instance-specific error occurred" when attempting to connect to Oracle DB?

I am trying to connect to an Oracle database using asp.net.

I have tns.ora entries set up correctly (I believe) in web.config file as shown below:

<add name="constr" connectionString="Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=myhostname)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=myServiceName)));User Id=myUsername;Password=myPassword;"/>

Then I use the connection string in codebehind:

Dim strConnString As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString

I declared Oracle Connection:

Imports System.Data.OracleClient

First, I am getting an error that

Namespace or Type declared in Imports System.Data.OracleClient
 doesn't contain any public member or is not found

When I removed it, I got the following error:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible...

I think that this has to do with Imports statement.

Any ideas how to fix this error?

Private Sub PopulateContinents() Dim oOracleConn As OracleConnection = New OracleConnection() Dim strConnString As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString

Dim strQuery As String = "select deptID, DeptName from Dept"
Dim con As OracleConnection = New SqlConnection(strConnString)
Dim cmd As OracleCommand = New SqlCommand
cmd.CommandType = CommandType.Text
cmd.CommandText = strQuery
cmd.Connection = con
oOracleConn.Open()
ddlContinents.DataSource = cmd.ExecuteReader
ddlContinents.DataTextField = "deptID"
ddlContinents.DataValueField = "DeptName"
ddlContinents.DataBind()
con.Close()

End Sub

Upvotes: 0

Views: 506

Answers (1)

rkawano
rkawano

Reputation: 2503

Its seems that the application is not getting the correct connection string.

First, try to clear all connection strings in web.config:

<connectionStrings>
  <clear />
  <add name="...

Second, try to specify the provider you want to use:

<add name="your.cs.name"
   providerName="Oracle.DataAccess.Client"
   connectionString="Data Source=//server:1521/instancename;User ID=UID;Password=PASS" />

Upvotes: 0

Related Questions