【发布时间】:2011-06-15 22:24:10
【问题描述】:
大家好,我对 Oracle 数据库非常陌生,我正在尝试通过 VB.net 2010 连接到它。我一直在尝试以下方法:
Dim myConnection As OleDbConnection
Dim myCommand As OleDbCommand
Dim dr As OleDbDataReader
myConnection = New OleDbConnection("Provider=MSDAORA.1;UserID=xxxx;password=xxxx; database=xxxx")
'MSDORA is the provider when working with Oracle
Try
myConnection.Open()
'opening the connection
myCommand = New OleDbCommand("Select * from emp", myConnection)
'executing the command and assigning it to connection
dr = myCommand.ExecuteReader()
While dr.Read()
'reading from the datareader
MessageBox.Show("EmpNo" & dr(0))
MessageBox.Show("EName" & dr(1))
MessageBox.Show("Job" & dr(2))
MessageBox.Show("Mgr" & dr(3))
MessageBox.Show("HireDate" & dr(4))
'displaying data from the table
End While
dr.Close()
myConnection.Close()
Catch ee As Exception
End Try
我在 Catch ee As Exception 行上收到错误:ORA-12560: TNS:protocol adapter error
我的计算机上还有一个 tnsnames.ora 文件,但我不确定在连接时是否需要使用它(或者实际上,首先如何使用)?上面的代码需要吗?
我正在尝试使用无 DNS 连接到数据库。不确定这是否是它在做的事情?
任何帮助都会很棒!!! :o)
大卫
【问题讨论】:
标签: vb.net oracle visual-studio-2010 connection-string ora-12560