使用VB.net将字符串连接到Oracle 10g DB
嘿,我对Oracle数据库很陌生,我正试图通过VB.net 2010连接到它。我一直在尝试以下方法:使用VB.net将字符串连接到Oracle 10g DB,vb.net,oracle,visual-studio-2010,connection-string,ora-12560,Vb.net,Oracle,Visual Studio 2010,Connection String,Ora 12560,嘿,我对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")
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上得到错误作为异常行:ORA-12560:TNS:protocoladapter error
我的电脑上也有一个tnsnames.ora文件,但我不确定在连接时是否需要使用它(或者说,一开始如何使用)?上面的代码需要它吗
我正在尝试使用与数据库的无DNS连接。不确定这是否是它在这方面所做的
任何帮助都会很好!!!:o)
David有很多方法:我几乎每次使用的方法都不需要在TNSNAMES.ORA中输入条目:
Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=MyHost)(PORT=MyPort)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=MyOracleSID)));User Id=myUsername;Password=myPassword;
如果您不需要OleDb连接,我认为您应该使用System.Data.OracleClient或任何其他免费提供商(如)
来源:当我需要创建到数据库的新连接字符串时,以及当连接字符串格式不在我头上时,我总是使用它。是这样吗?myConnection=New-OleDbConnection(“数据源=(描述=(地址\列表=(地址=(协议=TCP)(主机=MyHost)(端口=1521))(连接\数据=(服务器=专用)(服务\名称=MyOracleSID));用户Id=xxx;密码=xxx;”)如果要使用OleDbConnection,只需在
Provider=MSDAORA.1之前加上前缀代码>或使用Oracle适配器。请记住更改主机、端口(如果未使用默认端口)和服务名称。太棒了,我知道了!谢谢!:)