简体   繁体   English

连接到Oracle数据库

[英]Connecting to Oracle database

Today is my first day trying to use Oracle databases in Asp.NET so I have no idea of what I need to do. 今天是我尝试在Asp.NET中使用Oracle数据库的第一天,所以我不知道需要做什么。

I have added this code 我已添加此代码

Dim oOracleConn As OracleConnection = New OracleConnection()
oOracleConn.ConnectionString = "Data Source=xxxxx;User Id=yyy;Password=psw;"
oOracleConn.Open()
Response.write("Connected to Oracle.")
oOracleConn.Close()
oOracleConn.Dispose()
End Sub

But it gives me the error 但这给了我错误

Type 'OracleConnection' is not defined. 未定义类型“ OracleConnection”。

Now i've had a look on the internet and it says that it may be the reference to the DLL that is missing? 现在,我在互联网上看了一下,它说可能是缺少的DLL的参考?

I know I have got a DLL reference in my page and I don't think I even have the DLL anywhere on my server. 我知道我的页面上有一个DLL参考,而且我认为服务器上的任何地方都没有DLL。

Where do I get this DLL from? 我从哪里获得此DLL?

I've downloaded the ODBC .NET data provider but this didn't seem to help. 我已经下载了ODBC .NET数据提供程序,但这似乎无济于事。

I've tried to add a reference in Visual Studio but I can't find the Oracle client reference in the list. 我试图在Visual Studio中添加引用,但在列表中找不到Oracle客户端引用。

Any ideas? 有任何想法吗?

Thanks 谢谢

The Oracle recommended method is to use the Oracle Data Provider for .NET Oracle推荐的方法是使用Oracle Data Provider for .NET

You'll need an Oracle Client that is compatible with the version of the database you are using installed on your dev machine and the web sever machine. 您将需要一个与正在使用的数据库版本兼容的Oracle客户端,该客户端版本已安装在开发机和Web服务器上。

There are some quirks with how you have to specify the database connection string. 关于如何指定数据库连接字符串,有些问题。 Some kind internet soul has documented the database connection strings for the oracle providers. 某种形式的互联网灵魂已经为oracle提供程序记录了数据库连接字符串。

The oracle client has a file, called TNSNAMES.ORA, which is typically located in the /NETWORK/ADMIN folder under the oracle home where the client was installed (the installation location varies by version and installation settings). oracle客户端有一个名为TNSNAMES.ORA的文件,该文件通常位于安装了客户端的oracle主目录下的/ NETWORK / ADMIN文件夹中(安装位置因版本和安装设置而异)。

This file contains a list of databases with the Port Number, Hostname, and Oracle SID which allows the oracle client to make a connection to a server. 此文件包含具有端口号,主机名和Oracle SID的数据库列表,该列表允许oracle客户端建立与服务器的连接。

Once all of this is configured (or you decide to use the "TNS-less" connection string), you should be able to make database connections to oracle. 一旦配置了所有这些(或者您决定使用“无TNS”连接字符串),您就应该能够与oracle建立数据库连接。

The ODP.NET provider documentation also provides some sample code which is very helpful when getting started with it. ODP.NET提供程序文档还提供了一些示例代码,这些代码在入门时非常有用。

Per this , this OracleConnection is an obsolete API, however the DLL being used is: 就此而言 ,此OracleConnection是一个过时的API,但是所使用的DLL是:

System.Data.OracleClient.dll

EDIT: This article provides some data on different API's to connect to Oracle with .NET 编辑: 本文提供了有关不同API的一些数据,以通过.NET连接到Oracle

真正的问题是数据类型映射,但不是connection或provider。

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

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