欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

c#连接oracle数据库

程序员文章站 2022-03-23 19:22:16
连接字符串 public static string connString = "User ID=DatabaseName;Password=OraclePwd;Data Source=(DESCRIPTION = (ADDRESS_LIST= (ADDRESS = (PROTOCOL = TCP) ......

连接字符串

public static string connstring = "user id=databasename;password=oraclepwd;data source=(description = (address_list= (address = (protocol = tcp)(host = ipaddress)(port = 1521))) (connect_data = (service_name = orcl)))";

引用命名空间

using oracle.manageddataaccess.client;

连接方法

public int getconn()
{
oracleconnection conn = new oracleconnection(connstring);
int result = 0;
try
{
conn.open();
result = 1;
}
catch (exception ex)
{
throw (ex);
}
finally
{
conn.close();
}
return result;
}

在其他地方就可以调用这个方法使用了