我想用asp.net連接到Oracle數據庫。任何想法如何解決當試圖連接到Oracle DB時發生「與網絡相關或發生實例特定的錯誤」?
我已經設置了正確tns.ora條目(我相信)在web.config文件,如下圖所示:
<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
當我刪除它,我得到了以下錯誤:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible...
我認爲這與進口語句來完成。
任何想法如何解決這個錯誤?
私人小組PopulateContinents() 昏暗oOracleConn作爲的OracleConnection =新的OracleConnection() 昏暗strConnString作爲字符串= ConfigurationManager.ConnectionStrings( 「構造」)。的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()
結束子
錯誤是說,它可以」 t連接到數據庫,這通常意味着您的連接字符串不正確,例如你連接到一個不存在的服務器或許多其他潛在的問題。 – 2013-03-06 18:10:07
服務器確實存在。連接字符串在傳統ASP中完美工作。我調整了一點asp.net。所以,是的,服務器確實存在,連接字符串,我相信,作爲國家,是正確的。是我懷疑的進口可能沒有連接。 – 2013-03-06 18:25:11
您使用的是什麼種類的連接?第二次讀取錯誤是指MS SQL連接,所以它看起來像是試圖用連接字符串詳細信息連接到MS SQL DB。發佈您正在進行連接的代碼。 – 2013-03-06 18:27:54