我正在尝试使用 asp.net 连接到 Oracle 数据库。
我在 web.config 文件中正确设置了 tns.ora 条目(我相信),如下所示:
<add name="constr" connectionString="Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=myhostname)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=myServiceName)));User Id=myUsername;Password=myPassword;"/>
然后我在代码隐藏中使用连接字符串:
Dim strConnString As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
我声明了 Oracle 连接:
Imports System.Data.OracleClient
首先,我收到一个错误
Namespace or Type declared in Imports System.Data.OracleClient
doesn't contain any public member or is not found
当我删除它时,我收到以下错误:
建立与 SQL Server 的连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问...
我认为这与 Imports 声明有关。
任何想法如何解决这个错误?
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()
结束子