ADO.Net 链接 Oracle 数据库
Data Source=MyOracleDB;User Id=myUsername;Password=myPassword;
Integrated Security=no;
链接远程数据库:
1 static void Main(string[] args) 2 2 { 3 3 string conStr = @"SERVER=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=IP地址)(PORT=端口号))(CONNECT_DATA=(SERVICE_NAME=监听服务))); 4 4 uid=用户名;pwd=密码;"; 5 5 OracleConnection oracleConn = new OracleConnection(conStr); 6 6 //oracleConn.ConnectionString =@"User Id=system;Password=123456; 7 7 // Data Source=oracleSN;"; 8 8 oracleConn.Open(); 9 9 OracleCommand cmd = new OracleCommand("select * from \"UserInfo\"", oracleConn); 10 10 DataSet ds = new DataSet(); 11 11 OracleDataAdapter da = new OracleDataAdapter(cmd); 12 12 da.Fill(ds); 13 13 14 14 oracleConn.Close(); 15 15 } 16 17 复制代码
这是陈毅老师给的一个例子,链接而是远程的电脑,端口号合监听服务也是他自己设置的
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 7 using System.Data.OracleClient; 8 using System.Data; 9 10 11 namespace ConsoleApplication2 12 { 13 class Program 14 { 15 static void Main(string[] args) 16 { 17 string conStr = @"SERVER=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.129.119)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=orcl))); 18 uid=system;pwd=123456;"; 19 OracleConnection conn = new OracleConnection(conStr); 20 string sql="select * from \"LoginInfo\""; 21 OracleCommand cmd=new OracleCommand(sql,conn); 22 OracleDataAdapter da = new OracleDataAdapter(cmd); 23 DataSet ds = new DataSet(); 24 da.Fill(ds); 25 foreach (DataRow item in ds.Tables[0].Rows) 26 { 27 Console.WriteLine("ID:{0},Name:{1},pwd{2}",item["id"].ToString(),item["Name"].ToString(),item["pwd"].ToString()); 28 } 29 30 Console.ReadKey(); 31 } 32 } 33 }
posted on 2017-12-12 11:57 CCCCCC1129 阅读(142) 评论(0) 编辑 收藏 举报