执行插入时ORA-01745

时间:2014-05-12 07:05:40

标签: c# parameters insert oracle11g

以下ExecuteNonQuery返回sql错误:ORA-01745: invalid host/bind variable name,但正如您所看到的,这些参数名称不是保留字。为什么我会收到此错误? (我试图重命名所有参数)。

public bool AddArticle(ArticleModel articleModel)
        {
            bool result = false;
            using (OracleConnection conn = new OracleConnection(BasicConnection.connectionStringOracle))
            using (OracleCommand command = conn.CreateCommand())
            {
                conn.Open();
                using (var trans = conn.BeginTransaction())
                {
                    bool inserted = false;
                    string articleGuid = System.Guid.NewGuid().ToString().Replace("-", "");
                    command.CommandText = "INSERT INTO ARTICLE (ARTICLE.ID,USER_ID)" +
                        "VALUES(:aid,:auserId)";
                    command.Parameters.Add("aid", OracleDbType.Varchar2).Value = articleGuid;
                    command.Parameters.Add("auserId", OracleDbType.Varchar2).Value = articleModel.UserId;

                    inserted = (command.ExecuteNonQuery() == 1);
                    if (!inserted)
                    {
                        trans.Rollback();
                        return false;
                    }



                    command.CommandText = "INSERT INTO ARTICLE_CONTENT (LANG_ID,ARTICLE_ID,A_TITLE,A_CONTENT,ARTICLE_STATES_ID) "+
                        "VALUES(:alangId:, :aarticleId, :aatitle, :aacontent, :astateId)";
                    command.Parameters.Add("alangId", OracleDbType.Varchar2).Value = articleModel.Content.LangId;
                    command.Parameters.Add("aarticleId", OracleDbType.Varchar2).Value = articleGuid;
                    command.Parameters.Add("aatitle", OracleDbType.Varchar2).Value = articleModel.Content.ATitle;
                    command.Parameters.Add("aacontent", OracleDbType.Varchar2).Value = articleModel.Content.AContent;
                    command.Parameters.Add("astateId", OracleDbType.Varchar2).Value = articleModel.Content.ArticleStatesId;

                    inserted = (command.ExecuteNonQuery() == 1);
                    if (!inserted)
                    {
                        trans.Rollback();
                        return false;
                    }

                    trans.Commit();
                    result = true;
                }
            }

            return result;
        }

受影响的表格:

CREATE TABLE Article
  (
    id         VARCHAR2 (32) DEFAULT sys_guid() NOT NULL ,
    User_id    VARCHAR2 (32) NOT NULL ,
    created_at DATE DEFAULT sysdate ,
    updated_at DATE DEFAULT sysdate
  ) ;
ALTER TABLE Article ADD CONSTRAINT Article_PK PRIMARY KEY ( id ) ;

CREATE TABLE Article_Content
  (
    id         VARCHAR2 (32) DEFAULT sys_guid() NOT NULL ,
    Lang_id    VARCHAR2 (32) NOT NULL ,
    Article_id VARCHAR2 (32) NOT NULL ,
    a_title    VARCHAR2 (25) DEFAULT 'No-Title' NOT NULL ,
    a_content CLOB ,
    Article_States_id VARCHAR2 (32) NOT NULL
  ) ;
ALTER TABLE Article_Content ADD CONSTRAINT Article_Content_PK PRIMARY KEY ( id ) ;
ALTER TABLE Article_Content ADD CONSTRAINT Article_Content__UN UNIQUE ( a_title ) ;

CREATE TABLE Article_States
  (
    id      VARCHAR2 (32) DEFAULT sys_guid() NOT NULL ,
    a_state VARCHAR2 (50) DEFAULT 'ERROR'
  ) ;
ALTER TABLE Article_States ADD CONSTRAINT Article_States_PK PRIMARY KEY ( id ) ;

1 个答案:

答案 0 :(得分:0)

我的猜测是

中的尾随冒号
"VALUES(:alangId:, 

所以只是一个错字......