主要有两种方法,一种是直接写连接字符串,令一种是将连接字符串下载web.config文件中,下面分别作说明: 直接将写连接字符串: private static string connstr = data source=(description=(address_list=(address=(protocol=tcp)(host=mhost) (port=mport
主要有两种方法,一种是直接写连接字符串,令一种是将连接字符串下载web.config文件中,下面分别作说明:
直接将写连接字符串:
private static string connstr = data source=(description=(address_list=(address=(protocol=tcp)(host=mhost) (port=mport)))(connect_data=(service_name=mywervicename)));persist security info=true;user id=myusername; password=mypassword; private oracleconnection dbconn = new oracleconnection(connstr);
将连接字符串写在web.config文件中
private static string connstr = configurationmanager.connectionstrings[connectionstring].connectionstring;private oracleconnection dbconn = new oracleconnection(connstr);
这种方式的话要在配置文件中加入下面的配置信息
然后就可以打开连接并查询数据了
如下面
public void getdata() { if (dbconn.state == connectionstate.closed) { dbconn.open(); string quarystr = select * from tablename; oraclecommand comm = new oraclecommand(quarystr, dbconn); oracledatareader reader; reader = comm.executereader(); while (reader.read()) { string str = + reader.getstring(1); } } }
转载请注明:逝去日子的博客 » c#连接远程oracle数据库