sql >> Database teknologi >  >> RDS >> Oracle

Lange strenge i N-Hibernate med Oracle forårsager fejl

Dette er et kendt problem med det .NET-leverede System.Data.OracleClient.OracleConnection chauffør. Rettelsen er enten at bruge den Oracle-leverede ODP.net-klient Oracle.DataAccess.Client.OracleConnection (se:http://nuget.org/packages/odp.net.x86/) eller brug følgende løsning (refereret fra:http://thebasilet.blogspot.be/2009/07/nhibernate-oracle-clobs.html ).

public class CustomOracleDriver : OracleClientDriver
{
    protected override void InitializeParameter(System.Data.IDbDataParameter dbParam, string name, SqlType sqlType)
    {
        base.InitializeParameter(dbParam, name, sqlType);


        // System.Data.OracleClient.dll driver generates an ORA-01461 exception because 
        // the driver mistakenly infers the column type of the string being saved, and 
        // tries forcing the server to update a LONG value into a CLOB/NCLOB column type. 
        // The reason for the incorrect behavior is even more obscure and only happens 
        // when all the following conditions are met.
        //   1.) IDbDataParameter.Value = (string whose length: 4000 > length > 2000 )
        //   2.) IDbDataParameter.DbType = DbType.String
        //   3.) DB Column is of type NCLOB/CLOB

        // The above is the default behavior for NHibernate.OracleClientDriver
        // So we use the built-in StringClobSqlType to tell the driver to use the NClob Oracle type
        // This will work for both NCLOB/CLOBs without issues.
        // Mapping file must be updated to use StringClob as the property type
        // See: http://thebasilet.blogspot.be/2009/07/nhibernate-oracle-clobs.html
        if ((sqlType is StringClobSqlType))
        {
            ((OracleParameter)dbParam).OracleType = OracleType.NClob;
        }
    }
}

Du skal opdatere din SessionFactory for at bruge denne driver, samt opdatere enhver af dine clob-mappinger til at bruge StringClob tilpasset type

Map(x => x.EventType).CustomSqlType("Clob").CustomType("StringClob");



  1. Hvordan tilføjes indledende nul i et tal i Oracle SQL-forespørgsel?

  2. MySQL length() vs char_length()

  3. Proaktive SQL Server-sundhedstjek, del 2:Vedligeholdelse

  4. Sådan opretter du relationer i MySQL