Oracle数据库连接
2024-07-21 02:22:49
供稿:网友
odbc
new version:
"driver={microsoft odbc for oracle};server=oracleserver.world;uid=username;pwd=asdasd;"
old version:
"driver={microsoft odbc driver for oracle};connectstring=oracleserver.world;uid=myusername;pwd=mypassword;"
oledb, oledbconnection (.net)
standard security:
"provider=msdaora;data source=myoracledb;user id=username;password=asdasd;"
this one's from microsoft, the following are from oracle
standard security:
"provider=oraoledb.oracle;data source=myoracledb;user id=username;password=asdasd;"
trusted connection:
"provider=oraoledb.oracle;data source=myoracledb;osauthent=1;"
oracleconnection (.net)
standard:
"data source=oracle8i;integrated security=yes";
this one works only with oracle 8i release 3 or later
declare the oracleconnection:
c#:
using system.data.oracleclient;
oracleconnection ooracleconn = new oracleconnection();
ooracleconn.connectionstring = "my connectionstring";
ooracleconn.open();
vb.net:
imports system.data.oracleclient
dim ooracleconn as oracleconnection = new oracleconnection()
ooracleconn.connectionstring = "my connectionstring"
ooracleconn.open()
data shape
ms data shape:
"provider=msdatashape.1;persist security info=false;data provider=msdaora;data source=orac;user id=username;password=mypw"
例子1:namespace oracle
{
/// <summary>
/// webform1 的摘要说明。
/// </summary>
public class webform1 : system.web.ui.page
{
protected system.web.ui.webcontrols.datagrid datagrid1;
private dataset mydataset = new dataset();
private void page_load(object sender, system.eventargs e)
{
// 在此处放置用户代码以初始化页面
string connstring="provider=oraoledb.oracle;data source=jtest;user id=system;password=manager;";
oledbconnection conn=new oledbconnection(connstring);
string strcom = "select * from system.lg_task_table";
conn.open();
oledbdataadapter mycommand = new oledbdataadapter(strcom,conn);
mycommand.fill(mydataset,"system.lg_task_table");
datagrid1.datasource = mydataset.tables["system.lg_task_table"].defaultview;
datagrid1.databind();
conn.close();
}