简体   繁体   中英

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.

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.

Now i've had a look on the internet and it says that it may be the reference to the DLL that is missing?

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.

Where do I get this DLL from?

I've downloaded the ODBC .NET data provider but this didn't seem to help.

I've tried to add a reference in Visual Studio but I can't find the Oracle client reference in the list.

Any ideas?

Thanks

The Oracle recommended method is to use the 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.

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.

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).

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.

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.

The ODP.NET provider documentation also provides some sample code which is very helpful when getting started with it.

Per this , this OracleConnection is an obsolete API, however the DLL being used is:

System.Data.OracleClient.dll

EDIT: This article provides some data on different API's to connect to Oracle with .NET

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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