ASP.NET中连接Oracle问题:
对oracle数据库 连接,增,删,改,查操作的示例代码
1楼
MyConn = New System.Data.OleDb.OleDbConnection("Provider=MSDAORA.1;Data Source=oracle9;User ID=test;Password=test;")
2)定义并执行命令
Me.cmdinsert = New System.Data.OleDb.OleDbCommand()
'定义并设置命令的属性。
Me.cmdinsert.CommandText = "insert into table(name,old,nation) values('" & Me.Tname.Text & "'," & "to_date('" & Me.Told.Text & "','dd/mm/yy')" & ",'" & Me.Tnation.Text & "')"
Me.cmdinsert.CommandType = CommandType.Text
Me.cmdinsert.Connection = Me.MyConn
'打开数据库连接
Me.MyConn.Open()
'调用ExecuteNonQuery命令,执行无返回值的insert命令。
Me.cmdinsert.ExecuteNonQuery()
Me.MyConn.Close()
2 楼
(1)连接
string strconn = "data source=source;user=sa;password=sa;";
OracleConnection myConnection = new OracleConnection(strconn);
myConnection.Open();
(2)
string strsel = "select * from table_name";
or strsel = "insert into table(id,name) values('1','23')";
or strsel = "delete from table where id='1'";
OracleCommand mycom = new OracleCommand(strsel,myConnection);
mycom.ExecuteNonReader();
myConnection.Close();
3 楼lanyahuhu(宝姐姐和林妹妹,两个我都喜欢(补钙中))回复于 2003-10-17 09:20:29 得分 0 行
26:string sConn = System.Configuration.ConfigurationSettings.AppSettings["DbConn"];
行 27: m_Conn=new OleDbConnection(sConn);
行 28: m_Conn.Open();
报错如下 :
异常详细信息: System.Data.OleDb.OleDbException: 拒绝访问。
4 楼chinanewway(新路了无痕)回复于 2003-10-17 09:32:55 得分 0 我知道的,要么你的数据库不是信任连接,你就必须写上
user id和password,这样才能访问数据库;或者是你的oracle数据库服务未启动。
5 楼chinanewway(新路了无痕)回复于 2003-10-17 09:37:27 得分 0 在web.config文件中可以加入键值如下:
<appSettings>
<add key="oleDbConnection.ConnectionString" value="packet size=4096;user id=lamis;password=lamis;data source="LAMIS-SERVER";provider=SQLOLEDB;persist security info=False;initial catalog=lamis;workstation id=SOSORE" />
<add key="strConnection" value="data source=LAMIS-SERVER;initial catalog=lamis;persist security info=False;user id=lamis;password=lamis;workstation id=CXQ;packet size=4096" />
</appSettings>