诸子百家

采天地之灵气 汲日月之精华

DotNet访问Oracle

方法一:通过System.Data.OracleClient(需要安装Oracle客户端并配置tnsnames.ora)

string strcnn = "User ID=lportal;Password=lportal;Data Source=zhbrserverORCL;";

System.Data.OracleClient.OracleConnection cnn = new System.Data.OracleClient.OracleConnection(strcnn);

cnn.Open();

MessageBox.Show(cnn.State.ToString());

cnn.Close();

 

方法二:通过System.Data.OracleClient(需要安装Oracle客户端不需配置tnsnames.ora)

string strcnn = "User ID=lportal;Password=lportal;Data Source=(DESCRIPTION = (ADDRESS_LIST= (ADDRESS = (PROTOCOL = TCP)(HOST = zhbrserver)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = orcl)))";

System.Data.OracleClient.OracleConnection cnn = new System.Data.OracleClient.OracleConnection(strcnn);

cnn.Open();

MessageBox.Show(cnn.State.ToString());

cnn.Close();

 

方法三:通过System.Data.OleDbOracle公司的驱动

string strcnn = "Provider=OraOLEDB.Oracle.1;User ID=lportal;Password=lportal;Data Source=(DESCRIPTION = (ADDRESS_LIST= (ADDRESS = (PROTOCOL = TCP)(HOST = zhbrserver)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = orcl)))";

System.Data.OleDb.OleDbConnection cnn = new System.Data.OleDb.OleDbConnection(strcnn);

cnn.Open();

MessageBox.Show(cnn.State.ToString());

cnn.Close();

 

方法四:通过System.Data.OleDb和微软公司的Oracle驱动

string strcnn = "Provider=MSDAORA.1;User ID=lportal;Password=lportal;Data Source=(DESCRIPTION = (ADDRESS_LIST= (ADDRESS = (PROTOCOL = TCP)(HOST = zhbrserver)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = orcl)))";

System.Data.OleDb.OleDbConnection cnn = new System.Data.OleDb.OleDbConnection(strcnn);

cnn.Open();

MessageBox.Show(cnn.State.ToString());

cnn.Close();

备注:

1、   XP操作系统已经安装了微软公司的Oracle驱动C:/Program Files/Common Files/System/Ole DB/msdaora.dll

2、   该驱动需要Oracle客户端的三个文件(oraocixe10.dlloci.dllociw32.dll)方在System32下即可

====================================================

PS:使用Oracle公司提供的.net Provider也是不错的选择 

阅读更多
个人分类: Oracle C#
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

DotNet访问Oracle

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭