从C#连接到Oracle [英] Connect to oracle from c#
本文介绍了从C#连接到Oracle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从C#连接Oracle 11g.我已经按照[this link]定义了连接联盟,如下所示:
I am trying to connect Oracle 11g from C#. I have followed [this link], defined the connection allias like this:
moviess =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = xe)
)
)
在Visual Studio中尝试使用服务器资源管理器进行连接时,出现以下错误:
When trying to connect using server explorer in Visual studio it gives me the following error :
这是Oracle Developer Studio for Visual Studio的安装目录.
Here is the installation directory of the Oracle Developer Tool for Visual Studio.
我要去哪里错了?请帮助我.
Where am I going wrong ? Kindly assist me.
推荐答案
您可以从NuGet使用 Oracle ODP.Net驱动程序.
You can use Oracle ODP.Net Driver from NuGet.
您可以尝试以下操作:
- 右键单击参考,然后单击管理NuGet软件包.
- 选择 Oracle ODP.Net官方托管驱动程序
- Right-click on References and hit Manage NuGet packages.
- Select Official Oracle ODP.Net, Managed Driver
- 参考"Oracle.ManagedDataAccess.Client"
- 调用实际的连接.
以下是示例代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Oracle.ManagedDataAccess.Client;
namespace SampleOracle
{
class Program
{
static void Main(string[] args)
{
OracleConnection connection = new OracleConnection();
connection.ConnectionString = "User Id=<username>;Password=<password>;Data Source=<data source>"; //Data Source Format -> //IP_HOST:PORT/SERVICE_NAME e.g. //127.0.0.1:1521/Service_Name
connection.Open();
Console.WriteLine("Connected to Oracle" + connection.ServerVersion);
}
}
}
示例输出:
希望这会有所帮助!
这篇关于从C#连接到Oracle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文