“/zongtibu”应用程序中的服务器错误。
--------------------------------------------------------------------------------ORA-00001: unique constraint (CASIC.CASIC_PK) violated 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.OleDb.OleDbException: ORA-00001: unique constraint (CASIC.CASIC_PK) violated代码如下:private void Button_add_Click(object sender, System.EventArgs e)
{
cnn = new OleDbConnection("Provider=OraOLEDB.Oracle.1;Password=casic;Persist Security Info=True;User ID=casic;Data Source=ora8");
string cn1="Select DISTINCT ID,name,xinghao,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday from schedule";

da1=new OleDbDataAdapter();

da1.SelectCommand=new OleDbCommand(cn1,cnn);
string cn2 = "Insert Into schedule (ID,name,xinghao,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday) Values('"
                +TextBox_ID.Text+"','"+ TextBox_name.Text+"','"+TextBox_xinghao.Text+"','"
+ TextBox_Mon.Text+"','"+ TextBox_Tues.Text+"','" 
+ TextBox_Wed.Text+"','"+ TextBox_Thurs.Text+"','" 
+ TextBox_Fri.Text+"','"+ TextBox_Sat.Text+"','"
+ TextBox_Sun.Text+"')";

OleDbCommand cnn1 = new OleDbCommand();
cnn1.Connection = cnn;
cnn1.CommandText = cn2;
da1.InsertCommand = cnn1;
da1.UpdateCommand = cnn1;

ds1 = new DataSet();
da1.Fill(ds1,"work");
            DataTable table1 = ds1.Tables["work"];
DataRow newRow = table1.NewRow();
newRow["ID"] = TextBox_ID.Text.ToString();
newRow["name"] = TextBox_name.Text.ToString();
newRow["xinghao"] = TextBox_xinghao.Text.ToString();
newRow["Monday"] = TextBox_Mon.Text.ToString();
newRow["Tuesday"] = TextBox_Tues.Text.ToString();
newRow["Wednesday"] = TextBox_Wed.Text.ToString();
newRow["Thursday"] = TextBox_Thurs.Text.ToString();
newRow["Friday"] = TextBox_Fri.Text.ToString();
newRow["Saturday"] = TextBox_Sat.Text.ToString();
newRow["Sunday"] = TextBox_Sun.Text.ToString(); table1.Rows.Add(newRow);
da1.Update(ds1,"work");
Response.Write("<script language='javascript'>alert('添加成功!');</script>");

}
奇怪的是,如果添加的ID是以前没用过的,就能添加成功,如果用已存在的的ID,再运行这个函数,就会出现这个错误,大家帮忙看看是什么原因啊?
行 379:
行 380: table1.Rows.Add(newRow);
行 381: da1.Update(ds1,"work");
行 382: Response.Write("<script language='javascript'>alert('添加成功!');</script>");
行 383:
 源文件: c:\inetpub\wwwroot\zongtibu\webform1.aspx.cs    行: 381

解决方案 »

  1.   

    肯定能暂时解决问题方法就是暂时禁用唯一约束检查:
    ALTER TABLE PERFSTAT.STATS$SQL_SUMMARY 
    MODIFY CONSTRAINT STATS$SQL_SUMMARY_PK DISABLE NOVALIDATE;然后观察数据来发现根本问题,最后彻底解决之。到Metalink搜索了一下,发现存在一个相关Bug,Bug号为:2784796.
    在设置了cursor_sharing为similar或者force之后,可能触发此Bug,导致主键冲突。此bug据说在Oracle10g中已经修正。