Issues calling stored procedure from C# with large CLOB

前端 未结 4 1146
臣服心动
臣服心动 2020-12-09 03:55

I\'m not the first to have these issues, and will list some reference posts below, but am still looking for a proper solution.

I need to call a stored procedure (Ora

4条回答
  •  长情又很酷
    2020-12-09 04:37

    I found that there is another way to work around the problem! My fellow employee saved my day pointing me to this blog, which says:

    Set the parameter value when BeginTransaction has already been called on the DbConnection.

    Could it be simpler? The blog relates to Oracle.DataAccess, but it works just as well for System.Data.OracleClient.

    In practice this means:

    varcmd = new OracleCommand("LoadXML", _oracleConnection);
    cmd.CommandType = CommandType.StoredProcedure;
    
    var xmlParam = new OracleParameter("XMLFile", OracleType.Clob);
    cmd.Parameters.Add(xmlParam);
    
    // DO NOT assign the parameter value yet in this place
    
    cmd.Transaction = _oracleConnection.BeginTransaction();
    try
    {
        // Assign value here, AFTER starting the TX
        xmlParam.Value = xmlWithWayMoreThan4000Characters;
    
        cmd.ExecuteNonQuery();
        cmd.Transaction.Commit();
    }
    catch (OracleException)
    {
        cmd.Transaction.Rollback();
    }
    

提交回复
热议问题