首页 > 代码库 > 2011-03-17免Oracle客户端连远程Oracle的方法
2011-03-17免Oracle客户端连远程Oracle的方法
1、http://www.oracle.com/technetwork/topics/winsoft-085727.html上下载对应版本的instanctclinet zip包 34M 解压后92M 若要选择非32位操作系统找http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html
2、将包中的9个文件解压到system32目录下
3、添加System.Data.OracleClient引用
4、using System.Data.OracleClient 5、string connectionString = "Data Source=( DESCRIPTION = ( ADDRESS_LIST = ( ADDRESS = ( PROTOCOL = TCP )( HOST = 202.149.225.122 )( PORT = 1521 ) ) )( CONNECT_DATA = http://www.mamicode.com/( SERVICE_NAME = pub))); User Id= lahom; Password = jj;Unicode=True;"; //Unicode=True;是保证汉字不出现乱码的关键!!
OracleConnection cnn = new OracleConnection(connectionString);
cnn.Open();
OracleCommand cmd = cnn.CreateCommand();
cmd.CommandText = ("SELECT * from ad");
OracleDataAdapter myda = new OracleDataAdapter(cmd);
DataSet myds = new DataSet();
myda.Fill(myds);
MessageBox.Show(myds.Tables[0].Rows[0].ItemArray[2].ToString());
2011-03-17免Oracle客户端连远程Oracle的方法