连接到Oracle数据库 [英] Connect to an Oracle database
问题描述
我尝试连接到Oracle数据库,但是当代码执行该行时:
con = new OracleConnection(oradb);
它会出现此错误。 该程序无法启动,因为oraons.dll从您的计算机中丢失,请尝试重新安装程序来解决这个问题。我在我的计算机上已经从以下网站 http: //www.oracle.com/technetwork/topics/dotnet/index-085163.html 并引用Oracle.DataAccess。
我也检查了文件夹这是安装,我可以看到在文件夹中的oraons dll。下面是代码:
class OracleDatabase
{
OracleConnection con;
public void ConnectToOracleDb()
{
string oradb = getConnectionString(host,1521,sid,user,pass);
try
{
con = new OracleConnection(oradb);
con.Open();
Console.WriteLine(Connected to Oracle+ con.ServerVersion);
}
catch
{
Console.WriteLine(无法连接到FLX);
}
}
私人静态字符串getConnectionString(string databaseIP,int databasePort,string databaseSID,string databaseUN,string databasePW)
{
return string.Format(
Data Source =(DESCRIPTION =(ADDRESS =(PROTOCOL = TCP)(HOST = {0})(PORT = {1}))(CONNECT_DATA =(SID = {2}) ));+
Persist Security Info = True; User ID = {3}; Password = {4},
databaseIP,databasePort,databaseSID,databaseUN,databasePW
);
}
}
为什么我无法连接任何建议?
我最终引用了ManagedDataAccess.Client,而不仅仅是Data.Access.Client, >
I'm trying to connect to an Oracle database but when the the code is executing the line:
con = new OracleConnection(oradb);
It gives this error. "The program can't start because oraons.dll is missing from your computer. Try reinstalling the program to fix this problem." I installed the ODP for .net on my computer already from the following site http://www.oracle.com/technetwork/topics/dotnet/index-085163.html and referenced the Oracle.DataAccess.
I also checked the folder that was installed and I can see the oraons dll in the folder. Here's the code:
class OracleDatabase
{
OracleConnection con;
public void ConnectToOracleDb()
{
string oradb = getConnectionString("host", 1521, "sid", "user", "pass");
try
{
con = new OracleConnection(oradb);
con.Open();
Console.WriteLine("Connected to Oracle" + con.ServerVersion);
}
catch
{
Console.WriteLine("Could not connect to FLX");
}
}
private static string getConnectionString(string databaseIP, int databasePort, string databaseSID, string databaseUN, string databasePW)
{
return string.Format(
"Data Source=(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = {0})(PORT = {1}))(CONNECT_DATA =(SID = {2})));" +
"Persist Security Info=True;User ID={3};Password={4}",
databaseIP, databasePort, databaseSID, databaseUN, databasePW
);
}
}
Why can't I connect any suggestions?
I ended up referencing the ManagedDataAccess.Client instead of just the Data.Access.Client one and it worked.
这篇关于连接到Oracle数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!