VS环境下C#控制台远程连接oracle数据库无需安装客户端非常简单

时间:2022-06-27 05:51:00

VS环境下C#控制台远程连接oracle数据库无需安装客户端非常简单

新增加的引用:Oracle.ManagedDataAccess

并在命名空间增加:

using Oracle.ManagedDataAccess.Client;
直接上代码:

 public void setConnectionString()
{
string hostaddress = "IP";
string servername = "ABCD";
string uid = "ABC";
string pwd = "abc";
connectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=" + hostaddress + ")(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=" + servername + ")));Persist Security Info=True;User ID=" + uid + ";Password=" + pwd + ";";
}

 public void openConnection()
{
conn = new OracleConnection(connectionString);
conn.Open();
}
public void closeConnection()
{
conn.Close();
}
 DataReader ptDataReader;            DataTable datat = new DataTable();            ptDataReader = new DataReader();            ptDataReader.setConnectionString();            ptDataReader.openConnection();
如果有任何问题,欢迎评论,随时解答。