简体   繁体   English

使用VB.net连接到Oracle

[英]Connecting to Oracle with VB.net

I am using Oracle 11g, And I am trying to get it to connect to VB.net. 我正在使用Oracle 11g,并且正在尝试使其连接到VB.net。 I have installed the Oracle data provider. 我已经安装了Oracle数据提供程序。 I have access to the tnsnames.ora under the samples folder. 我可以访问samples文件夹下的tnsnames.ora。 However I for some reason cannot locate the listener.ora file. 但是由于某种原因,我无法找到listener.ora文件。 When trying to connect to the database I get the following error: ORA-12560: TNS: protocol adapter error. 尝试连接到数据库时,出现以下错误:ORA-12560:TNS:协议适配器错误。 I have tried to get my database running through the services but there isn't one which shows my database. 我试图通过服务运行我的数据库,但是没有一个显示我的数据库。

Hope I was clear and I would any suggestions why there isn't a listener file and why this error is occurring. 希望我很清楚,我将对为什么没有侦听器文件以及为什么发生此错误提出任何建议。 I have tried through tutorials, using this link http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/dotnet/GettingStartedVBVersion/GettingStartedNET_VBVersion.htm and also used the wizard but still get the same error message. 我已经尝试过使用此链接http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/dotnet/GettingStartedVBVersion/GettingStartedNET_VBVersion.htm的教程,并且使用了该向导,但仍然收到相同的错误消息。

OK.Install the ODAC with odt for your database.(32 bit).Don't edit and tns details and add the referenece to the oracledataaccess.dll to your project. 好的。为您的数据库安装odt的ODAC。(32位)。不要编辑和tns详细信息,而是将Referenece添加到oracledataaccess.dll中到您的项目中。 Import these two 导入这两个

Imports Oracle.DataAccess.Client
Imports Oracle.DataAccess.Types

Then add the lines 然后添加行

Dim oradb As String = "Data Source=*your tns entry goes here*" + "User Id=uname;Password=pass;"
Dim conn As New OracleConnection(oradb)
conn.open()

This did the job for me. 这为我做了工作。 If it works ,add the data in your tns file as it is not advised to keep the connection string in the code. 如果可行,请在您的tns文件中添加数据,因为不建议将连接字符串保留在代码中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM