一个关于orale数据库的配置的问题。我在c#程序中连接orale数据库的时候,总是连接不上,程序如下:
//string conStr="provider=sqloledb;server=(local);database=pubs;uid=sa;password=123";
string conStr="provider=oraoledb.oracle;user id=tmmsapp;data source=dotnet;password=hello; Connect Timeout=5";
OleDbConnection conn=new OleDbConnection(conStr);
try
{
conn.Open();
// OleDbDataAdapter da=new OleDbDataAdapter("select * from workers",conn);
// DataSet ds=new DataSet();
// da.Fill(ds);
// this.dataGrid1.DataSource=ds.Tables[0];
conn.Close();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
MessageBox.Show(ex.Source);
MessageBox.Show(ex.HelpLink );
}
结果程序执行到conn.open()的时候,就出现异常,异常的提示信息为:"多步 OLE DB 操作产生错误。如果可能,请检查每个 OLE DB 状态值。没有工作被完成。" 我还是使用OleDbConnection ,改为连接sqlserver2000数据库,即以上程序中只是把连接字符串改了一下,则程序能够正常执行.看来应该是orale数据库出现的问题吧?我装的是orale9.0的客户端(administrator),在它的net manager中测试连接该数据库正常,只是在登陆net manager开始的时候,出现了一个错误提示对话框,上面写着:unable to connect to directory.这是什么意思啊,是不是导致程序中oledb无法正常连接数据库的原因呢?
应该如何消除这个对话框啊,我把客户端重装了3遍了!但每次都提示这样一个错误,这是怎么回事啊。
急啊,不然又要重做系统了!累啊,亟盼好心大哥大姐回复!!
附:异常信息的详细信息:
出现异常错误(orale.net.common.datastore.DatastoreException).消息:unable to construct LDAPDatastore:null admin context
原因:
oracle.net.common.dataStore.DataStoreException: unable to construct LDAPDataStore: null admin context
at oracle.net.common.dataStore.LDAPDataStore.<init>(LDAPDataStore.java)
at oracle.net.mgr.container.NetContainer.initClient(Compiled Code)
at oracle.sysman.emSDK.client.appComponent.BaseAppComponent.init(BaseAppComponent.java:242)
at oracle.sysman.emSDK.client.appContainer.WebApplication.addApplicationComponent(WebApplication.java:1089)
at oracle.net.mgr.container.NetApplication.init(NetApplication.java)
at oracle.sysman.emSDK.client.appContainer.WebApplication.launch(WebApplication.java:3155)
at oracle.sysman.emSDK.client.appContainer.WebApplication.main(WebApplication.java:3047)
提示:我所连的orale数据库是我们局域网上的。
9 个解决方案
#1
string conStr="Provider=MSDAORA;user id=tmmsapp;data source=dotnet;password=hello; Connect Timeout=5";
試試
試試
#2
这应该是配置oracle实例的问题
你配时选择tcp/ip, 打上机器IP,端口默认,
比如建好一个实例叫 abc
那你直接通过Provider=MSDAORA.1;Password=11;User ID=user;Data Source=abc
就能访问了
如果实例没配好, c#估计也帮不上忙
不知道你需要什么。。。随便给你贴一个把。。。不过连接ORACLE数据库需要微软的一个补丁。。。不知道你有没有~要不用ole db连接很痛苦的。而且老出错
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration ;
namespace ad
{
/// <summary>
/// adresourse 的摘要说明。
/// </summary>
public class adresourse : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.Button Button1;
private string cons="";
private System.Data.OracleClient.OracleConnection myconnection = new System.Data.OracleClient.OracleConnection();
private void Page_Load(object sender, System.EventArgs e)
{
if (!this.IsPostBack )
{
Session["page"]=0;
}
string ShcameName = ConfigurationSettings.AppSettings["source"];
string ServiceName = ConfigurationSettings.AppSettings["id"];
string service=ConfigurationSettings.AppSettings["catalog"];
cons="User ID="+ShcameName.ToString()+";password="+service+";Data Source="+ServiceName.ToString()+";Persist Security Info=False";
myconnection.ConnectionString = cons;
int k;
k = int.Parse(Session["page"].ToString());
k++;
Session["page"]=k;
if (k!=3)
{
string myselectquery = "SELECT * FROM adresourse";
DataSet mydataset=new DataSet();
System.Data.OracleClient.OracleCommand myselectcommand = new System.Data.OracleClient.OracleCommand(myselectquery, myconnection);
myconnection.Open();
System.Data.OracleClient.OracleDataAdapter myadapter=new System.Data.OracleClient.OracleDataAdapter();
myadapter.SelectCommand = new System.Data.OracleClient.OracleCommand(myselectquery, myconnection);
myadapter.Fill(mydataset);
DataGrid1.DataSource=mydataset.Tables[0];
DataGrid1.DataBind();
myconnection.Close();
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.DataGrid1.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_CancelCommand);
this.DataGrid1.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_EditCommand);
this.DataGrid1.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_UpdateCommand);
this.DataGrid1.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_DeleteCommand);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
void BindGrid()
{
string myselectquery = "SELECT * FROM adresourse";
DataSet mydataset=new DataSet();
myconnection.ConnectionString = cons;
System.Data.OracleClient.OracleCommand myselectcommand = new System.Data.OracleClient.OracleCommand(myselectquery, myconnection);
myconnection.Open();
System.Data.OracleClient.OracleDataAdapter myadapter=new System.Data.OracleClient.OracleDataAdapter();
myadapter.SelectCommand = new System.Data.OracleClient.OracleCommand(myselectquery, myconnection);
myadapter.Fill(mydataset);
DataGrid1.DataSource=mydataset.Tables[0];
DataGrid1.DataBind();
myconnection.Close();
}
private void Button1_Click(object sender, System.EventArgs e)
{
string str="insert into adresourse(locationid,locationdesc,width,height,url) VALUES ('','',0,0,'')";
myconnection.Open();
System.Data.OracleClient.OracleCommand comm =new System.Data.OracleClient.OracleCommand(str,myconnection);
try
{
comm.ExecuteNonQuery();
//Message.InnerHtml = "<b>已插入记录</b><br/>" + updateCmd;
DataGrid1.EditItemIndex = -1;}
catch{}
Session["page"]=1;
myconnection.Close();
BindGrid();
}
private void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex=e.Item.ItemIndex;
DataGrid1.DataBind();
}
private void DataGrid1_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex=-1;
DataBind();
Session["page"]=1;
string myselectquery = "SELECT * FROM adresourse";
DataSet mydataset=new DataSet();
System.Data.OracleClient.OracleCommand myselectcommand = new System.Data.OracleClient.OracleCommand(myselectquery, myconnection);
myconnection.Open();
System.Data.OracleClient.OracleDataAdapter myadapter=new System.Data.OracleClient.OracleDataAdapter();
myadapter.SelectCommand = new System.Data.OracleClient.OracleCommand(myselectquery, myconnection);
myadapter.Fill(mydataset);
DataGrid1.DataSource=mydataset.Tables[0];
DataGrid1.DataBind();
myconnection.Close();
}
private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
String updateCmd = "UPDATE adresourse SET locationid='";
updateCmd+=((TextBox)e.Item.Cells[2].Controls[0]).Text+"', locationdesc ='"+((TextBox)e.Item.Cells[3].Controls[0]).Text +"', width='"+((TextBox)e.Item.Cells[5].Controls[0]).Text +"',"
+ "height = '"+((TextBox)e.Item.Cells[4].Controls[0]).Text +"', url ='"+((TextBox)e.Item.Cells[6].Controls[0]).Text +"' where id='"+e.Item.Cells[1].Text +"'" ;
myconnection.Open();
System.Data.OracleClient.OracleCommand comm =new System.Data.OracleClient.OracleCommand(updateCmd,myconnection);
try
{
comm.ExecuteNonQuery();
//Message.InnerHtml = "<b>已更新记录</b><br/>" + updateCmd;
DataGrid1.EditItemIndex = -1;
}
catch
{}
myconnection.Close();
Session["page"]=1;
BindGrid();
}
private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
String updateCmd = "delete from adresourse where id='"+ e.Item.Cells[1].Text+"'";
myconnection.Open();
System.Data.OracleClient.OracleCommand comm =new System.Data.OracleClient.OracleCommand(updateCmd,myconnection);
try
{
comm.ExecuteNonQuery();
//Message.InnerHtml = "<b>已更新记录</b><br/>" + updateCmd;
DataGrid1.EditItemIndex = -1;
}
catch
{}
myconnection.Close();
Session["page"]=1;
BindGrid();
}
}
}
你配时选择tcp/ip, 打上机器IP,端口默认,
比如建好一个实例叫 abc
那你直接通过Provider=MSDAORA.1;Password=11;User ID=user;Data Source=abc
就能访问了
如果实例没配好, c#估计也帮不上忙
不知道你需要什么。。。随便给你贴一个把。。。不过连接ORACLE数据库需要微软的一个补丁。。。不知道你有没有~要不用ole db连接很痛苦的。而且老出错
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration ;
namespace ad
{
/// <summary>
/// adresourse 的摘要说明。
/// </summary>
public class adresourse : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.Button Button1;
private string cons="";
private System.Data.OracleClient.OracleConnection myconnection = new System.Data.OracleClient.OracleConnection();
private void Page_Load(object sender, System.EventArgs e)
{
if (!this.IsPostBack )
{
Session["page"]=0;
}
string ShcameName = ConfigurationSettings.AppSettings["source"];
string ServiceName = ConfigurationSettings.AppSettings["id"];
string service=ConfigurationSettings.AppSettings["catalog"];
cons="User ID="+ShcameName.ToString()+";password="+service+";Data Source="+ServiceName.ToString()+";Persist Security Info=False";
myconnection.ConnectionString = cons;
int k;
k = int.Parse(Session["page"].ToString());
k++;
Session["page"]=k;
if (k!=3)
{
string myselectquery = "SELECT * FROM adresourse";
DataSet mydataset=new DataSet();
System.Data.OracleClient.OracleCommand myselectcommand = new System.Data.OracleClient.OracleCommand(myselectquery, myconnection);
myconnection.Open();
System.Data.OracleClient.OracleDataAdapter myadapter=new System.Data.OracleClient.OracleDataAdapter();
myadapter.SelectCommand = new System.Data.OracleClient.OracleCommand(myselectquery, myconnection);
myadapter.Fill(mydataset);
DataGrid1.DataSource=mydataset.Tables[0];
DataGrid1.DataBind();
myconnection.Close();
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.DataGrid1.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_CancelCommand);
this.DataGrid1.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_EditCommand);
this.DataGrid1.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_UpdateCommand);
this.DataGrid1.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_DeleteCommand);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
void BindGrid()
{
string myselectquery = "SELECT * FROM adresourse";
DataSet mydataset=new DataSet();
myconnection.ConnectionString = cons;
System.Data.OracleClient.OracleCommand myselectcommand = new System.Data.OracleClient.OracleCommand(myselectquery, myconnection);
myconnection.Open();
System.Data.OracleClient.OracleDataAdapter myadapter=new System.Data.OracleClient.OracleDataAdapter();
myadapter.SelectCommand = new System.Data.OracleClient.OracleCommand(myselectquery, myconnection);
myadapter.Fill(mydataset);
DataGrid1.DataSource=mydataset.Tables[0];
DataGrid1.DataBind();
myconnection.Close();
}
private void Button1_Click(object sender, System.EventArgs e)
{
string str="insert into adresourse(locationid,locationdesc,width,height,url) VALUES ('','',0,0,'')";
myconnection.Open();
System.Data.OracleClient.OracleCommand comm =new System.Data.OracleClient.OracleCommand(str,myconnection);
try
{
comm.ExecuteNonQuery();
//Message.InnerHtml = "<b>已插入记录</b><br/>" + updateCmd;
DataGrid1.EditItemIndex = -1;}
catch{}
Session["page"]=1;
myconnection.Close();
BindGrid();
}
private void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex=e.Item.ItemIndex;
DataGrid1.DataBind();
}
private void DataGrid1_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex=-1;
DataBind();
Session["page"]=1;
string myselectquery = "SELECT * FROM adresourse";
DataSet mydataset=new DataSet();
System.Data.OracleClient.OracleCommand myselectcommand = new System.Data.OracleClient.OracleCommand(myselectquery, myconnection);
myconnection.Open();
System.Data.OracleClient.OracleDataAdapter myadapter=new System.Data.OracleClient.OracleDataAdapter();
myadapter.SelectCommand = new System.Data.OracleClient.OracleCommand(myselectquery, myconnection);
myadapter.Fill(mydataset);
DataGrid1.DataSource=mydataset.Tables[0];
DataGrid1.DataBind();
myconnection.Close();
}
private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
String updateCmd = "UPDATE adresourse SET locationid='";
updateCmd+=((TextBox)e.Item.Cells[2].Controls[0]).Text+"', locationdesc ='"+((TextBox)e.Item.Cells[3].Controls[0]).Text +"', width='"+((TextBox)e.Item.Cells[5].Controls[0]).Text +"',"
+ "height = '"+((TextBox)e.Item.Cells[4].Controls[0]).Text +"', url ='"+((TextBox)e.Item.Cells[6].Controls[0]).Text +"' where id='"+e.Item.Cells[1].Text +"'" ;
myconnection.Open();
System.Data.OracleClient.OracleCommand comm =new System.Data.OracleClient.OracleCommand(updateCmd,myconnection);
try
{
comm.ExecuteNonQuery();
//Message.InnerHtml = "<b>已更新记录</b><br/>" + updateCmd;
DataGrid1.EditItemIndex = -1;
}
catch
{}
myconnection.Close();
Session["page"]=1;
BindGrid();
}
private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
String updateCmd = "delete from adresourse where id='"+ e.Item.Cells[1].Text+"'";
myconnection.Open();
System.Data.OracleClient.OracleCommand comm =new System.Data.OracleClient.OracleCommand(updateCmd,myconnection);
try
{
comm.ExecuteNonQuery();
//Message.InnerHtml = "<b>已更新记录</b><br/>" + updateCmd;
DataGrid1.EditItemIndex = -1;
}
catch
{}
myconnection.Close();
Session["page"]=1;
BindGrid();
}
}
}
#3
连接字符串改为如下:
Provider=OraOLEDB.Oracle.1;Persist Security Info=False;user id=tmmsapp;data source=dotnet;password=hello;
Provider=OraOLEDB.Oracle.1;Persist Security Info=False;user id=tmmsapp;data source=dotnet;password=hello;
#4
如果 orale9.0的客户端(administrator),在它的net manager中测试连接该数据库正常,
用MS提供的orale连接试试:
Provider=MSDAORA.1;Password=hello;User ID=tmmsapp;Data Source=dotnet;Persist Security Info=True
连接溢出时间短了点
Connect Timeout=5
用MS提供的orale连接试试:
Provider=MSDAORA.1;Password=hello;User ID=tmmsapp;Data Source=dotnet;Persist Security Info=True
连接溢出时间短了点
Connect Timeout=5
#5
string conStr = "Password=xxx;User ID=xxx;Data Source=xxx.xx.x.x;Provider=OraOLEDB.Oracle.1";
#6
首先要用Oracle自己的OLEDB驱动,如果是9i,客户端应该自带.
其次用Provider=MSDAORA.1;Password=yourPWD;User ID=yourName;Data Source=yourClientName;Persist Security Info=True
其次用Provider=MSDAORA.1;Password=yourPWD;User ID=yourName;Data Source=yourClientName;Persist Security Info=True
#7
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.Button Button1;
private string cons="";
private System.Data.OracleClient.OracleConnection myconnection = new System.Data.OracleClient.OracleConnection();
cons="User ID="+ShcameName.ToString()+";password="+service+";Data Source="+ServiceName.ToString()+";Persist Security Info=False";
myconnection.ConnectionString = cons;
myconnection。Open();
protected System.Web.UI.WebControls.Button Button1;
private string cons="";
private System.Data.OracleClient.OracleConnection myconnection = new System.Data.OracleClient.OracleConnection();
cons="User ID="+ShcameName.ToString()+";password="+service+";Data Source="+ServiceName.ToString()+";Persist Security Info=False";
myconnection.ConnectionString = cons;
myconnection。Open();
#8
Provider=MSDAORA.1;Password=hello;User ID=tmmsapp;Data Source=dotnet;Persist Security Info=True
#9
谢谢大家的答复,问题已经解决,就是我在安装客户端的时候,第一次安装出现了个问题,以后重装便没有用了。出现的问题是,我不知怎么把网络目录的配置给搞坏了,D:\oracle\ora90\network\ADMIN目录下有个配置文件tnsnames.ora,正常的配置应该只有这一个文件,而我可能安装过程中配置了,但又取消了,垃圾文件(*.cfg,*.ora)还留着,影响了正常启动。把这些文件删掉便好了。
sql plus也正常了。
sql plus也正常了。
#1
string conStr="Provider=MSDAORA;user id=tmmsapp;data source=dotnet;password=hello; Connect Timeout=5";
試試
試試
#2
这应该是配置oracle实例的问题
你配时选择tcp/ip, 打上机器IP,端口默认,
比如建好一个实例叫 abc
那你直接通过Provider=MSDAORA.1;Password=11;User ID=user;Data Source=abc
就能访问了
如果实例没配好, c#估计也帮不上忙
不知道你需要什么。。。随便给你贴一个把。。。不过连接ORACLE数据库需要微软的一个补丁。。。不知道你有没有~要不用ole db连接很痛苦的。而且老出错
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration ;
namespace ad
{
/// <summary>
/// adresourse 的摘要说明。
/// </summary>
public class adresourse : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.Button Button1;
private string cons="";
private System.Data.OracleClient.OracleConnection myconnection = new System.Data.OracleClient.OracleConnection();
private void Page_Load(object sender, System.EventArgs e)
{
if (!this.IsPostBack )
{
Session["page"]=0;
}
string ShcameName = ConfigurationSettings.AppSettings["source"];
string ServiceName = ConfigurationSettings.AppSettings["id"];
string service=ConfigurationSettings.AppSettings["catalog"];
cons="User ID="+ShcameName.ToString()+";password="+service+";Data Source="+ServiceName.ToString()+";Persist Security Info=False";
myconnection.ConnectionString = cons;
int k;
k = int.Parse(Session["page"].ToString());
k++;
Session["page"]=k;
if (k!=3)
{
string myselectquery = "SELECT * FROM adresourse";
DataSet mydataset=new DataSet();
System.Data.OracleClient.OracleCommand myselectcommand = new System.Data.OracleClient.OracleCommand(myselectquery, myconnection);
myconnection.Open();
System.Data.OracleClient.OracleDataAdapter myadapter=new System.Data.OracleClient.OracleDataAdapter();
myadapter.SelectCommand = new System.Data.OracleClient.OracleCommand(myselectquery, myconnection);
myadapter.Fill(mydataset);
DataGrid1.DataSource=mydataset.Tables[0];
DataGrid1.DataBind();
myconnection.Close();
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.DataGrid1.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_CancelCommand);
this.DataGrid1.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_EditCommand);
this.DataGrid1.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_UpdateCommand);
this.DataGrid1.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_DeleteCommand);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
void BindGrid()
{
string myselectquery = "SELECT * FROM adresourse";
DataSet mydataset=new DataSet();
myconnection.ConnectionString = cons;
System.Data.OracleClient.OracleCommand myselectcommand = new System.Data.OracleClient.OracleCommand(myselectquery, myconnection);
myconnection.Open();
System.Data.OracleClient.OracleDataAdapter myadapter=new System.Data.OracleClient.OracleDataAdapter();
myadapter.SelectCommand = new System.Data.OracleClient.OracleCommand(myselectquery, myconnection);
myadapter.Fill(mydataset);
DataGrid1.DataSource=mydataset.Tables[0];
DataGrid1.DataBind();
myconnection.Close();
}
private void Button1_Click(object sender, System.EventArgs e)
{
string str="insert into adresourse(locationid,locationdesc,width,height,url) VALUES ('','',0,0,'')";
myconnection.Open();
System.Data.OracleClient.OracleCommand comm =new System.Data.OracleClient.OracleCommand(str,myconnection);
try
{
comm.ExecuteNonQuery();
//Message.InnerHtml = "<b>已插入记录</b><br/>" + updateCmd;
DataGrid1.EditItemIndex = -1;}
catch{}
Session["page"]=1;
myconnection.Close();
BindGrid();
}
private void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex=e.Item.ItemIndex;
DataGrid1.DataBind();
}
private void DataGrid1_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex=-1;
DataBind();
Session["page"]=1;
string myselectquery = "SELECT * FROM adresourse";
DataSet mydataset=new DataSet();
System.Data.OracleClient.OracleCommand myselectcommand = new System.Data.OracleClient.OracleCommand(myselectquery, myconnection);
myconnection.Open();
System.Data.OracleClient.OracleDataAdapter myadapter=new System.Data.OracleClient.OracleDataAdapter();
myadapter.SelectCommand = new System.Data.OracleClient.OracleCommand(myselectquery, myconnection);
myadapter.Fill(mydataset);
DataGrid1.DataSource=mydataset.Tables[0];
DataGrid1.DataBind();
myconnection.Close();
}
private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
String updateCmd = "UPDATE adresourse SET locationid='";
updateCmd+=((TextBox)e.Item.Cells[2].Controls[0]).Text+"', locationdesc ='"+((TextBox)e.Item.Cells[3].Controls[0]).Text +"', width='"+((TextBox)e.Item.Cells[5].Controls[0]).Text +"',"
+ "height = '"+((TextBox)e.Item.Cells[4].Controls[0]).Text +"', url ='"+((TextBox)e.Item.Cells[6].Controls[0]).Text +"' where id='"+e.Item.Cells[1].Text +"'" ;
myconnection.Open();
System.Data.OracleClient.OracleCommand comm =new System.Data.OracleClient.OracleCommand(updateCmd,myconnection);
try
{
comm.ExecuteNonQuery();
//Message.InnerHtml = "<b>已更新记录</b><br/>" + updateCmd;
DataGrid1.EditItemIndex = -1;
}
catch
{}
myconnection.Close();
Session["page"]=1;
BindGrid();
}
private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
String updateCmd = "delete from adresourse where id='"+ e.Item.Cells[1].Text+"'";
myconnection.Open();
System.Data.OracleClient.OracleCommand comm =new System.Data.OracleClient.OracleCommand(updateCmd,myconnection);
try
{
comm.ExecuteNonQuery();
//Message.InnerHtml = "<b>已更新记录</b><br/>" + updateCmd;
DataGrid1.EditItemIndex = -1;
}
catch
{}
myconnection.Close();
Session["page"]=1;
BindGrid();
}
}
}
你配时选择tcp/ip, 打上机器IP,端口默认,
比如建好一个实例叫 abc
那你直接通过Provider=MSDAORA.1;Password=11;User ID=user;Data Source=abc
就能访问了
如果实例没配好, c#估计也帮不上忙
不知道你需要什么。。。随便给你贴一个把。。。不过连接ORACLE数据库需要微软的一个补丁。。。不知道你有没有~要不用ole db连接很痛苦的。而且老出错
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration ;
namespace ad
{
/// <summary>
/// adresourse 的摘要说明。
/// </summary>
public class adresourse : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.Button Button1;
private string cons="";
private System.Data.OracleClient.OracleConnection myconnection = new System.Data.OracleClient.OracleConnection();
private void Page_Load(object sender, System.EventArgs e)
{
if (!this.IsPostBack )
{
Session["page"]=0;
}
string ShcameName = ConfigurationSettings.AppSettings["source"];
string ServiceName = ConfigurationSettings.AppSettings["id"];
string service=ConfigurationSettings.AppSettings["catalog"];
cons="User ID="+ShcameName.ToString()+";password="+service+";Data Source="+ServiceName.ToString()+";Persist Security Info=False";
myconnection.ConnectionString = cons;
int k;
k = int.Parse(Session["page"].ToString());
k++;
Session["page"]=k;
if (k!=3)
{
string myselectquery = "SELECT * FROM adresourse";
DataSet mydataset=new DataSet();
System.Data.OracleClient.OracleCommand myselectcommand = new System.Data.OracleClient.OracleCommand(myselectquery, myconnection);
myconnection.Open();
System.Data.OracleClient.OracleDataAdapter myadapter=new System.Data.OracleClient.OracleDataAdapter();
myadapter.SelectCommand = new System.Data.OracleClient.OracleCommand(myselectquery, myconnection);
myadapter.Fill(mydataset);
DataGrid1.DataSource=mydataset.Tables[0];
DataGrid1.DataBind();
myconnection.Close();
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.DataGrid1.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_CancelCommand);
this.DataGrid1.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_EditCommand);
this.DataGrid1.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_UpdateCommand);
this.DataGrid1.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_DeleteCommand);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
void BindGrid()
{
string myselectquery = "SELECT * FROM adresourse";
DataSet mydataset=new DataSet();
myconnection.ConnectionString = cons;
System.Data.OracleClient.OracleCommand myselectcommand = new System.Data.OracleClient.OracleCommand(myselectquery, myconnection);
myconnection.Open();
System.Data.OracleClient.OracleDataAdapter myadapter=new System.Data.OracleClient.OracleDataAdapter();
myadapter.SelectCommand = new System.Data.OracleClient.OracleCommand(myselectquery, myconnection);
myadapter.Fill(mydataset);
DataGrid1.DataSource=mydataset.Tables[0];
DataGrid1.DataBind();
myconnection.Close();
}
private void Button1_Click(object sender, System.EventArgs e)
{
string str="insert into adresourse(locationid,locationdesc,width,height,url) VALUES ('','',0,0,'')";
myconnection.Open();
System.Data.OracleClient.OracleCommand comm =new System.Data.OracleClient.OracleCommand(str,myconnection);
try
{
comm.ExecuteNonQuery();
//Message.InnerHtml = "<b>已插入记录</b><br/>" + updateCmd;
DataGrid1.EditItemIndex = -1;}
catch{}
Session["page"]=1;
myconnection.Close();
BindGrid();
}
private void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex=e.Item.ItemIndex;
DataGrid1.DataBind();
}
private void DataGrid1_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex=-1;
DataBind();
Session["page"]=1;
string myselectquery = "SELECT * FROM adresourse";
DataSet mydataset=new DataSet();
System.Data.OracleClient.OracleCommand myselectcommand = new System.Data.OracleClient.OracleCommand(myselectquery, myconnection);
myconnection.Open();
System.Data.OracleClient.OracleDataAdapter myadapter=new System.Data.OracleClient.OracleDataAdapter();
myadapter.SelectCommand = new System.Data.OracleClient.OracleCommand(myselectquery, myconnection);
myadapter.Fill(mydataset);
DataGrid1.DataSource=mydataset.Tables[0];
DataGrid1.DataBind();
myconnection.Close();
}
private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
String updateCmd = "UPDATE adresourse SET locationid='";
updateCmd+=((TextBox)e.Item.Cells[2].Controls[0]).Text+"', locationdesc ='"+((TextBox)e.Item.Cells[3].Controls[0]).Text +"', width='"+((TextBox)e.Item.Cells[5].Controls[0]).Text +"',"
+ "height = '"+((TextBox)e.Item.Cells[4].Controls[0]).Text +"', url ='"+((TextBox)e.Item.Cells[6].Controls[0]).Text +"' where id='"+e.Item.Cells[1].Text +"'" ;
myconnection.Open();
System.Data.OracleClient.OracleCommand comm =new System.Data.OracleClient.OracleCommand(updateCmd,myconnection);
try
{
comm.ExecuteNonQuery();
//Message.InnerHtml = "<b>已更新记录</b><br/>" + updateCmd;
DataGrid1.EditItemIndex = -1;
}
catch
{}
myconnection.Close();
Session["page"]=1;
BindGrid();
}
private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
String updateCmd = "delete from adresourse where id='"+ e.Item.Cells[1].Text+"'";
myconnection.Open();
System.Data.OracleClient.OracleCommand comm =new System.Data.OracleClient.OracleCommand(updateCmd,myconnection);
try
{
comm.ExecuteNonQuery();
//Message.InnerHtml = "<b>已更新记录</b><br/>" + updateCmd;
DataGrid1.EditItemIndex = -1;
}
catch
{}
myconnection.Close();
Session["page"]=1;
BindGrid();
}
}
}
#3
连接字符串改为如下:
Provider=OraOLEDB.Oracle.1;Persist Security Info=False;user id=tmmsapp;data source=dotnet;password=hello;
Provider=OraOLEDB.Oracle.1;Persist Security Info=False;user id=tmmsapp;data source=dotnet;password=hello;
#4
如果 orale9.0的客户端(administrator),在它的net manager中测试连接该数据库正常,
用MS提供的orale连接试试:
Provider=MSDAORA.1;Password=hello;User ID=tmmsapp;Data Source=dotnet;Persist Security Info=True
连接溢出时间短了点
Connect Timeout=5
用MS提供的orale连接试试:
Provider=MSDAORA.1;Password=hello;User ID=tmmsapp;Data Source=dotnet;Persist Security Info=True
连接溢出时间短了点
Connect Timeout=5
#5
string conStr = "Password=xxx;User ID=xxx;Data Source=xxx.xx.x.x;Provider=OraOLEDB.Oracle.1";
#6
首先要用Oracle自己的OLEDB驱动,如果是9i,客户端应该自带.
其次用Provider=MSDAORA.1;Password=yourPWD;User ID=yourName;Data Source=yourClientName;Persist Security Info=True
其次用Provider=MSDAORA.1;Password=yourPWD;User ID=yourName;Data Source=yourClientName;Persist Security Info=True
#7
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.Button Button1;
private string cons="";
private System.Data.OracleClient.OracleConnection myconnection = new System.Data.OracleClient.OracleConnection();
cons="User ID="+ShcameName.ToString()+";password="+service+";Data Source="+ServiceName.ToString()+";Persist Security Info=False";
myconnection.ConnectionString = cons;
myconnection。Open();
protected System.Web.UI.WebControls.Button Button1;
private string cons="";
private System.Data.OracleClient.OracleConnection myconnection = new System.Data.OracleClient.OracleConnection();
cons="User ID="+ShcameName.ToString()+";password="+service+";Data Source="+ServiceName.ToString()+";Persist Security Info=False";
myconnection.ConnectionString = cons;
myconnection。Open();
#8
Provider=MSDAORA.1;Password=hello;User ID=tmmsapp;Data Source=dotnet;Persist Security Info=True
#9
谢谢大家的答复,问题已经解决,就是我在安装客户端的时候,第一次安装出现了个问题,以后重装便没有用了。出现的问题是,我不知怎么把网络目录的配置给搞坏了,D:\oracle\ora90\network\ADMIN目录下有个配置文件tnsnames.ora,正常的配置应该只有这一个文件,而我可能安装过程中配置了,但又取消了,垃圾文件(*.cfg,*.ora)还留着,影响了正常启动。把这些文件删掉便好了。
sql plus也正常了。
sql plus也正常了。