EF + ODP.NET + CLOB = Value Cannot be Null - Parameter name: byteArray?












11














Our project recently updated to the newer Oracle.ManagedDataAccess DLL's (v 4.121.2.0) and this error has been cropping up intermittently. We've fixed it a few times without really knowing what we did to fix it.



I'm fairly certain it's caused by CLOB fields being mapped to strings in Entity Framework, and then being selected in LINQ statements that pull entire entities instead of just a limited set of properties.



Error:



Value cannot be null.
Parameter name: byteArray


Stack Trace:



   at System.BitConverter.ToString(Byte value, Int32 startIndex, Int32 length)
at OracleInternal.TTC.TTCLob.GetLobIdString(Byte lobLocator)
at OracleInternal.ServiceObjects.OracleDataReaderImpl.CollectTempLOBsToBeFreed(Int32 rowNumber)
at Oracle.ManagedDataAccess.Client.OracleDataReader.ProcessAnyTempLOBs(Int32 rowNumber)
at Oracle.ManagedDataAccess.Client.OracleDataReader.Read()
at System.Data.Entity.Core.Common.Internal.Materialization.Shaper`1.StoreRead()


Suspect Entity Properties:



'Mapped to Oracle CLOB Column'
<Column("LARGEFIELD")>
Public Property LargeField As String


But I'm confident this is the proper way to map the fields per Oracle's matrix:



ODP.NET Types Overview



There is nothing obviously wrong with the generated SQL statement either:



SELECT 
...
"Extent1"."LARGEFIELD" AS "LARGEFIELD",
...
FROM ... "Extent1"
WHERE ...


I have also tried this Fluent code per Ozkan's suggestion, but it does not seem to affect my case.



modelBuilder.Entity(Of [CLASS])().Property(
Function(x) x.LargeField
).IsOptional()


Troubleshooting Update:



After extensive testing, we are quite certain this is actually a bug, not a configuration problem. It appears to be the contents of the CLOB that cause the problem under a very specific set of circumstances. I've cross-posted this on the Oracle Forums, hoping for more information.










share|improve this question




















  • 2




    Hi, have you found any fix for this? Using the last version from nuget here and still getting the same error. Thanks.
    – Edgar Carvalho
    Feb 27 '16 at 20:57






  • 1




    I am on 4.121.2.0 and I can't find a viable solution, either. Once again, forced to work around an Oracle managed driver issue.
    – James R.
    Jun 30 '16 at 19:43
















11














Our project recently updated to the newer Oracle.ManagedDataAccess DLL's (v 4.121.2.0) and this error has been cropping up intermittently. We've fixed it a few times without really knowing what we did to fix it.



I'm fairly certain it's caused by CLOB fields being mapped to strings in Entity Framework, and then being selected in LINQ statements that pull entire entities instead of just a limited set of properties.



Error:



Value cannot be null.
Parameter name: byteArray


Stack Trace:



   at System.BitConverter.ToString(Byte value, Int32 startIndex, Int32 length)
at OracleInternal.TTC.TTCLob.GetLobIdString(Byte lobLocator)
at OracleInternal.ServiceObjects.OracleDataReaderImpl.CollectTempLOBsToBeFreed(Int32 rowNumber)
at Oracle.ManagedDataAccess.Client.OracleDataReader.ProcessAnyTempLOBs(Int32 rowNumber)
at Oracle.ManagedDataAccess.Client.OracleDataReader.Read()
at System.Data.Entity.Core.Common.Internal.Materialization.Shaper`1.StoreRead()


Suspect Entity Properties:



'Mapped to Oracle CLOB Column'
<Column("LARGEFIELD")>
Public Property LargeField As String


But I'm confident this is the proper way to map the fields per Oracle's matrix:



ODP.NET Types Overview



There is nothing obviously wrong with the generated SQL statement either:



SELECT 
...
"Extent1"."LARGEFIELD" AS "LARGEFIELD",
...
FROM ... "Extent1"
WHERE ...


I have also tried this Fluent code per Ozkan's suggestion, but it does not seem to affect my case.



modelBuilder.Entity(Of [CLASS])().Property(
Function(x) x.LargeField
).IsOptional()


Troubleshooting Update:



After extensive testing, we are quite certain this is actually a bug, not a configuration problem. It appears to be the contents of the CLOB that cause the problem under a very specific set of circumstances. I've cross-posted this on the Oracle Forums, hoping for more information.










share|improve this question




















  • 2




    Hi, have you found any fix for this? Using the last version from nuget here and still getting the same error. Thanks.
    – Edgar Carvalho
    Feb 27 '16 at 20:57






  • 1




    I am on 4.121.2.0 and I can't find a viable solution, either. Once again, forced to work around an Oracle managed driver issue.
    – James R.
    Jun 30 '16 at 19:43














11












11








11


4





Our project recently updated to the newer Oracle.ManagedDataAccess DLL's (v 4.121.2.0) and this error has been cropping up intermittently. We've fixed it a few times without really knowing what we did to fix it.



I'm fairly certain it's caused by CLOB fields being mapped to strings in Entity Framework, and then being selected in LINQ statements that pull entire entities instead of just a limited set of properties.



Error:



Value cannot be null.
Parameter name: byteArray


Stack Trace:



   at System.BitConverter.ToString(Byte value, Int32 startIndex, Int32 length)
at OracleInternal.TTC.TTCLob.GetLobIdString(Byte lobLocator)
at OracleInternal.ServiceObjects.OracleDataReaderImpl.CollectTempLOBsToBeFreed(Int32 rowNumber)
at Oracle.ManagedDataAccess.Client.OracleDataReader.ProcessAnyTempLOBs(Int32 rowNumber)
at Oracle.ManagedDataAccess.Client.OracleDataReader.Read()
at System.Data.Entity.Core.Common.Internal.Materialization.Shaper`1.StoreRead()


Suspect Entity Properties:



'Mapped to Oracle CLOB Column'
<Column("LARGEFIELD")>
Public Property LargeField As String


But I'm confident this is the proper way to map the fields per Oracle's matrix:



ODP.NET Types Overview



There is nothing obviously wrong with the generated SQL statement either:



SELECT 
...
"Extent1"."LARGEFIELD" AS "LARGEFIELD",
...
FROM ... "Extent1"
WHERE ...


I have also tried this Fluent code per Ozkan's suggestion, but it does not seem to affect my case.



modelBuilder.Entity(Of [CLASS])().Property(
Function(x) x.LargeField
).IsOptional()


Troubleshooting Update:



After extensive testing, we are quite certain this is actually a bug, not a configuration problem. It appears to be the contents of the CLOB that cause the problem under a very specific set of circumstances. I've cross-posted this on the Oracle Forums, hoping for more information.










share|improve this question















Our project recently updated to the newer Oracle.ManagedDataAccess DLL's (v 4.121.2.0) and this error has been cropping up intermittently. We've fixed it a few times without really knowing what we did to fix it.



I'm fairly certain it's caused by CLOB fields being mapped to strings in Entity Framework, and then being selected in LINQ statements that pull entire entities instead of just a limited set of properties.



Error:



Value cannot be null.
Parameter name: byteArray


Stack Trace:



   at System.BitConverter.ToString(Byte value, Int32 startIndex, Int32 length)
at OracleInternal.TTC.TTCLob.GetLobIdString(Byte lobLocator)
at OracleInternal.ServiceObjects.OracleDataReaderImpl.CollectTempLOBsToBeFreed(Int32 rowNumber)
at Oracle.ManagedDataAccess.Client.OracleDataReader.ProcessAnyTempLOBs(Int32 rowNumber)
at Oracle.ManagedDataAccess.Client.OracleDataReader.Read()
at System.Data.Entity.Core.Common.Internal.Materialization.Shaper`1.StoreRead()


Suspect Entity Properties:



'Mapped to Oracle CLOB Column'
<Column("LARGEFIELD")>
Public Property LargeField As String


But I'm confident this is the proper way to map the fields per Oracle's matrix:



ODP.NET Types Overview



There is nothing obviously wrong with the generated SQL statement either:



SELECT 
...
"Extent1"."LARGEFIELD" AS "LARGEFIELD",
...
FROM ... "Extent1"
WHERE ...


I have also tried this Fluent code per Ozkan's suggestion, but it does not seem to affect my case.



modelBuilder.Entity(Of [CLASS])().Property(
Function(x) x.LargeField
).IsOptional()


Troubleshooting Update:



After extensive testing, we are quite certain this is actually a bug, not a configuration problem. It appears to be the contents of the CLOB that cause the problem under a very specific set of circumstances. I've cross-posted this on the Oracle Forums, hoping for more information.







oracle entity-framework entity-framework-6 odp.net odp.net-managed






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 25 '15 at 19:41

























asked Feb 18 '15 at 20:43









Tom Halladay

3,89353858




3,89353858








  • 2




    Hi, have you found any fix for this? Using the last version from nuget here and still getting the same error. Thanks.
    – Edgar Carvalho
    Feb 27 '16 at 20:57






  • 1




    I am on 4.121.2.0 and I can't find a viable solution, either. Once again, forced to work around an Oracle managed driver issue.
    – James R.
    Jun 30 '16 at 19:43














  • 2




    Hi, have you found any fix for this? Using the last version from nuget here and still getting the same error. Thanks.
    – Edgar Carvalho
    Feb 27 '16 at 20:57






  • 1




    I am on 4.121.2.0 and I can't find a viable solution, either. Once again, forced to work around an Oracle managed driver issue.
    – James R.
    Jun 30 '16 at 19:43








2




2




Hi, have you found any fix for this? Using the last version from nuget here and still getting the same error. Thanks.
– Edgar Carvalho
Feb 27 '16 at 20:57




Hi, have you found any fix for this? Using the last version from nuget here and still getting the same error. Thanks.
– Edgar Carvalho
Feb 27 '16 at 20:57




1




1




I am on 4.121.2.0 and I can't find a viable solution, either. Once again, forced to work around an Oracle managed driver issue.
– James R.
Jun 30 '16 at 19:43




I am on 4.121.2.0 and I can't find a viable solution, either. Once again, forced to work around an Oracle managed driver issue.
– James R.
Jun 30 '16 at 19:43












6 Answers
6






active

oldest

votes


















1














We met this problem in our project an hour ago and found a solution. It is generating this error because of null values in CLOB caolumn. We have a CLOB column and it is Nullable in database. In EntityFramework model it is String but not Nullable. We changed column's Nullable property to True in EF model and it fixed problem.






share|improve this answer





















  • Good suggestion. I've tried it on my project (see added code), but with no success.
    – Tom Halladay
    Feb 19 '15 at 16:00





















1














We have this problem as well on some computers, and we are running the latest Oracle.ManagedDataAccess.dll (4.121.2.20150926 ODAC RELEASE 4).



We found a solution to our problem, and I just wanted to share.



This was our problem that occurred some computers.



Using connection As New OracleConnection(yourConnectionString)
Dim command As New OracleCommand(yourQuery, connection)
connection.Open()

Using reader As OracleDataReader = command.ExecuteReader()
Dim clobField As String = CStr(reader.Item("CLOB_FIELD"))
End Using

connection.Close()
End Using


And here's the solution that made it work on all computers.



Using connection As New OracleConnection(yourConnectionString)
Dim command As New OracleCommand(yourQuery, connection)
connection.Open()

Using reader As OracleDataReader = command.ExecuteReader()
Dim clobField As String = reader.GetOracleClob(0).Value
End Using

connection.Close()
End Using





share|improve this answer





























    1














    I spent a lot of time trying to decipher this and found bits of this and that here and there on the internet, but no where had everything in one place, so I'd like to post what I've learned, and how I resolved it, which is much like Ragowit's answer, but I've got the C# code for it.



    Background

    The error: So I had this error on my while (dr.Read()) line:



    Value cannot be null. rnParmeter name: byteArray


    I ran into very little on the internet about this, except that it was an error with the CLOB field when it was null, and was supposedly fixed in the latest ODAC release, according to this: https://community.oracle.com/thread/3944924



    My take on this -- NOT TRUE! It hasn't been updated since October 5, 2015 (http://www.oracle.com/technetwork/topics/dotnet/utilsoft-086879.html), and the 12c package I'm using was downloaded in April 2016.



    Full stack trace by someone else with the error that pretty much mirrored mine: http://pastebin.com/24AfFDnq



    Value cannot be null.
    Parameter name: byteArray

    at System.BitConverter.ToString(Byte value, Int32 startIndex, Int32 length)
    at OracleInternal.TTC.TTCLob.GetLobIdString(Byte lobLocator)
    at OracleInternal.ServiceObjects.OracleDataReaderImpl.CollectTempLOBsToBeFreed(Int32 rowNumber)
    at Oracle.ManagedDataAccess.Client.OracleDataReader.ProcessAnyTempLOBs(Int32 rowNumber)
    at Oracle.ManagedDataAccess.Client.OracleDataReader.Read()
    at System.Data.Entity.Core.Common.Internal.Materialization.Shaper`1.StoreRead()

    'Mapped to Oracle CLOB Column'
    <Column("LARGEFIELD")>
    Public Property LargeField As String

    'Mapped to Oracle BLOB Column'
    <Column("IMAGE")>
    Public Property FileContents As Byte()


    How I encountered it: It was while reading an 11-column table of about 3000 rows. One of the columns was actually an NCLOB (so apparently this is just as susceptible as CLOB), which allowed nulls in the database, and some of its values were empty - it was an optional "Notes" field, after all. It's funny that I didn't get this error on the first or even second row that had an empty Notes field. It didn't error until row 768 finished and it was about to start row 769, according to an int counter variable that started at 0 that I set up and saw after checking how many rows my DataTable had thus far. I found I got the error if I used:



    DataSet ds = new DataSet();
    OracleDataAdapter adapter = new OracleDataAdapter(cmd);
    adapter.Fill(ds);


    as well if I used:



    DataTable dt = new DataTable();
    OracleDataReader dr = cmd.ExecuteReader();
    dt.Load(dr);


    or if I used:



    OracleDataReader dr = cmd.ExecuteReader();
    if (dr.HasRows)
    {
    while (dr.Read())
    {
    ....
    }
    }


    where cmd is the OracleCommand, so it made no difference.



    Resolution


    The following is basically the code I used to parse through an OracleDataReader values in order to assign them to a DataTable. It's actually not as refined as it could be - I am using it to just return dr[i] to datarow in all cases except when the value is null, and when it is the eleventh column (index = 10, because it starts at 0) and a particular query has been executed so that I know where my NCLOB column is.



    public static DataTable GetDataTableManually(string query)
    {
    OracleConnection conn = null;
    try
    {
    string connString = ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString;
    conn = new OracleConnection(connString);
    OracleCommand cmd = new OracleCommand(query, conn);
    conn.Open();
    OracleDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
    DataTable dtSchema = dr.GetSchemaTable();
    DataTable dt = new DataTable();

    List<DataColumn> listCols = new List<DataColumn>();
    List<DataColumn> listTypes = new List<DataColumn>();

    if (dtSchema != null)
    {
    foreach (DataRow drow in dtSchema.Rows)
    {
    string columnName = System.Convert.ToString(drow["ColumnName"]);
    DataColumn column = new DataColumn(columnName, (Type)(drow["DataType"]));
    listCols.Add(column);
    listTypes.Add(drow["DataType"].ToString()); // necessary in order to record nulls
    dt.Columns.Add(column);
    }
    }

    // Read rows from DataReader and populate the DataTable
    if (dr.HasRows)
    {
    int rowCount = 0;
    while (dr.Read())
    {
    string fieldType = String.Empty;
    DataRow dataRow = dt.NewRow();

    for (int i = 0; i < dr.FieldCount; i++)
    {
    if (!dr.IsDBNull[i])
    {
    fieldType = dr.GetFieldType(i).ToString(); // example only, this is the same as listTypes[i], and neither help us distinguish NCLOB from NVARCHAR2 - both will say System.String

    // This is the magic
    if (query == "SELECT * FROM Orders" && i == 10)
    dataRow[((DataColumn)listCols[i])] = dr.GetOracleClob(i); // <-- our new check!!!!
    // Found if you have null Decimal fields, this is
    // also needed, and GetOracleDecimal and GetDecimal
    // will not help you - only GetFloat does
    else if (listTypes[i] == "System.Decimal")
    dataRow[((DataColumn)listCols[i])] = dr.GetFloat(i);
    else
    dataRow[((DataColumn)listCols[i])] = dr[i];
    }
    else // value was null; we can't always assign dr[i] if DBNull, such as when it is a number or decimal field
    {
    byte nullArray = new byte[0];
    switch (listTypes[i])
    {
    case "System.String": // includes NVARCHAR2, CLOB, NCLOB, etc.
    dataRow[((DataColumn)listCols[i])] = String.Empty;
    break;
    case "System.Decimal":
    case "System.Int16": // Boolean
    case "System.Int32": // Number
    dataRow[((DataColumn)listCols[i])] = 0;
    break;
    case "System.DateTime":
    dataRow[((DataColumn)listCols[i])] = DBNull.Value;
    break;
    case "System.Byte": // Blob
    dataRow[((DataColumn)listCols[i])] = nullArray;
    break;
    default:
    dataRow[((DataColumn)listCols[i])] = String.Empty;
    break;
    }
    }
    }
    dt.Rows.Add(dataRow);
    }
    ds.Tables.Add(dt);
    }

    }
    catch (Exception ex)
    {
    // handle error
    }
    finally
    {
    conn.Close();
    }

    // After everything is closed
    if (ds.Tables.Count > 0)
    return ds.Tables[0]; // there should only be one table if we got results
    else
    return null;

    }


    In the same way that I have it assigning specific types of null based on the column type found in the schema table loop, you could add the conditions to the "not null" side of the if...then and do various GetOracle... statements there. I found it was only necessary for this NCLOB instance, though.



    To give credit where credit is due, the original codebase is based on the answer given by sarathkumar at Populate data table from data reader .






    share|improve this answer































      0














      For me it was simple! I had this error with odac v 4.121.1.0. I have just updated Oracle.ManagedDataAccess to 4.121.2.0 with Nuget and now it is working.



      Have you have tried to uninstall and reinstall Oracle.ManagedDataAccess with Nugget?






      share|improve this answer































        0














        After installation of Oracle12 client we ran into the same problem.
        In machine.config (C:WindowsMicrosoft.NETFrameworkv4.0.30319Config) I removed all entries with Oracle.ManagedDataAccess.
        In directory C:WindowsMicrosoft.NETassemblyGAC_MSIL I removed both Oracle.ManagedDataAccess and Policy.4.121.Oracle.ManagedDataAccess.
        Then my C# program started working as usually, using the Oracle.ManagedDataAccess dll in it's own directory.






        share|improve this answer





























          0














          upgrade Oracle.ManagedDataAccess.dll to version 4.122.1.0 solved.
          If you are using vs 2017, we can update via NuGet.



          enter image description here






          share|improve this answer





















          • Error appears again even with latest version. Solved by add nvl() to clob column in oracle procedure.
            – Song
            Jun 27 at 2:49











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f28593520%2fef-odp-net-clob-value-cannot-be-null-parameter-name-bytearray%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          6 Answers
          6






          active

          oldest

          votes








          6 Answers
          6






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          We met this problem in our project an hour ago and found a solution. It is generating this error because of null values in CLOB caolumn. We have a CLOB column and it is Nullable in database. In EntityFramework model it is String but not Nullable. We changed column's Nullable property to True in EF model and it fixed problem.






          share|improve this answer





















          • Good suggestion. I've tried it on my project (see added code), but with no success.
            – Tom Halladay
            Feb 19 '15 at 16:00


















          1














          We met this problem in our project an hour ago and found a solution. It is generating this error because of null values in CLOB caolumn. We have a CLOB column and it is Nullable in database. In EntityFramework model it is String but not Nullable. We changed column's Nullable property to True in EF model and it fixed problem.






          share|improve this answer





















          • Good suggestion. I've tried it on my project (see added code), but with no success.
            – Tom Halladay
            Feb 19 '15 at 16:00
















          1












          1








          1






          We met this problem in our project an hour ago and found a solution. It is generating this error because of null values in CLOB caolumn. We have a CLOB column and it is Nullable in database. In EntityFramework model it is String but not Nullable. We changed column's Nullable property to True in EF model and it fixed problem.






          share|improve this answer












          We met this problem in our project an hour ago and found a solution. It is generating this error because of null values in CLOB caolumn. We have a CLOB column and it is Nullable in database. In EntityFramework model it is String but not Nullable. We changed column's Nullable property to True in EF model and it fixed problem.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Feb 19 '15 at 14:32









          Ozkan

          111




          111












          • Good suggestion. I've tried it on my project (see added code), but with no success.
            – Tom Halladay
            Feb 19 '15 at 16:00




















          • Good suggestion. I've tried it on my project (see added code), but with no success.
            – Tom Halladay
            Feb 19 '15 at 16:00


















          Good suggestion. I've tried it on my project (see added code), but with no success.
          – Tom Halladay
          Feb 19 '15 at 16:00






          Good suggestion. I've tried it on my project (see added code), but with no success.
          – Tom Halladay
          Feb 19 '15 at 16:00















          1














          We have this problem as well on some computers, and we are running the latest Oracle.ManagedDataAccess.dll (4.121.2.20150926 ODAC RELEASE 4).



          We found a solution to our problem, and I just wanted to share.



          This was our problem that occurred some computers.



          Using connection As New OracleConnection(yourConnectionString)
          Dim command As New OracleCommand(yourQuery, connection)
          connection.Open()

          Using reader As OracleDataReader = command.ExecuteReader()
          Dim clobField As String = CStr(reader.Item("CLOB_FIELD"))
          End Using

          connection.Close()
          End Using


          And here's the solution that made it work on all computers.



          Using connection As New OracleConnection(yourConnectionString)
          Dim command As New OracleCommand(yourQuery, connection)
          connection.Open()

          Using reader As OracleDataReader = command.ExecuteReader()
          Dim clobField As String = reader.GetOracleClob(0).Value
          End Using

          connection.Close()
          End Using





          share|improve this answer


























            1














            We have this problem as well on some computers, and we are running the latest Oracle.ManagedDataAccess.dll (4.121.2.20150926 ODAC RELEASE 4).



            We found a solution to our problem, and I just wanted to share.



            This was our problem that occurred some computers.



            Using connection As New OracleConnection(yourConnectionString)
            Dim command As New OracleCommand(yourQuery, connection)
            connection.Open()

            Using reader As OracleDataReader = command.ExecuteReader()
            Dim clobField As String = CStr(reader.Item("CLOB_FIELD"))
            End Using

            connection.Close()
            End Using


            And here's the solution that made it work on all computers.



            Using connection As New OracleConnection(yourConnectionString)
            Dim command As New OracleCommand(yourQuery, connection)
            connection.Open()

            Using reader As OracleDataReader = command.ExecuteReader()
            Dim clobField As String = reader.GetOracleClob(0).Value
            End Using

            connection.Close()
            End Using





            share|improve this answer
























              1












              1








              1






              We have this problem as well on some computers, and we are running the latest Oracle.ManagedDataAccess.dll (4.121.2.20150926 ODAC RELEASE 4).



              We found a solution to our problem, and I just wanted to share.



              This was our problem that occurred some computers.



              Using connection As New OracleConnection(yourConnectionString)
              Dim command As New OracleCommand(yourQuery, connection)
              connection.Open()

              Using reader As OracleDataReader = command.ExecuteReader()
              Dim clobField As String = CStr(reader.Item("CLOB_FIELD"))
              End Using

              connection.Close()
              End Using


              And here's the solution that made it work on all computers.



              Using connection As New OracleConnection(yourConnectionString)
              Dim command As New OracleCommand(yourQuery, connection)
              connection.Open()

              Using reader As OracleDataReader = command.ExecuteReader()
              Dim clobField As String = reader.GetOracleClob(0).Value
              End Using

              connection.Close()
              End Using





              share|improve this answer












              We have this problem as well on some computers, and we are running the latest Oracle.ManagedDataAccess.dll (4.121.2.20150926 ODAC RELEASE 4).



              We found a solution to our problem, and I just wanted to share.



              This was our problem that occurred some computers.



              Using connection As New OracleConnection(yourConnectionString)
              Dim command As New OracleCommand(yourQuery, connection)
              connection.Open()

              Using reader As OracleDataReader = command.ExecuteReader()
              Dim clobField As String = CStr(reader.Item("CLOB_FIELD"))
              End Using

              connection.Close()
              End Using


              And here's the solution that made it work on all computers.



              Using connection As New OracleConnection(yourConnectionString)
              Dim command As New OracleCommand(yourQuery, connection)
              connection.Open()

              Using reader As OracleDataReader = command.ExecuteReader()
              Dim clobField As String = reader.GetOracleClob(0).Value
              End Using

              connection.Close()
              End Using






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 2 '16 at 10:34









              Ragowit

              7627




              7627























                  1














                  I spent a lot of time trying to decipher this and found bits of this and that here and there on the internet, but no where had everything in one place, so I'd like to post what I've learned, and how I resolved it, which is much like Ragowit's answer, but I've got the C# code for it.



                  Background

                  The error: So I had this error on my while (dr.Read()) line:



                  Value cannot be null. rnParmeter name: byteArray


                  I ran into very little on the internet about this, except that it was an error with the CLOB field when it was null, and was supposedly fixed in the latest ODAC release, according to this: https://community.oracle.com/thread/3944924



                  My take on this -- NOT TRUE! It hasn't been updated since October 5, 2015 (http://www.oracle.com/technetwork/topics/dotnet/utilsoft-086879.html), and the 12c package I'm using was downloaded in April 2016.



                  Full stack trace by someone else with the error that pretty much mirrored mine: http://pastebin.com/24AfFDnq



                  Value cannot be null.
                  Parameter name: byteArray

                  at System.BitConverter.ToString(Byte value, Int32 startIndex, Int32 length)
                  at OracleInternal.TTC.TTCLob.GetLobIdString(Byte lobLocator)
                  at OracleInternal.ServiceObjects.OracleDataReaderImpl.CollectTempLOBsToBeFreed(Int32 rowNumber)
                  at Oracle.ManagedDataAccess.Client.OracleDataReader.ProcessAnyTempLOBs(Int32 rowNumber)
                  at Oracle.ManagedDataAccess.Client.OracleDataReader.Read()
                  at System.Data.Entity.Core.Common.Internal.Materialization.Shaper`1.StoreRead()

                  'Mapped to Oracle CLOB Column'
                  <Column("LARGEFIELD")>
                  Public Property LargeField As String

                  'Mapped to Oracle BLOB Column'
                  <Column("IMAGE")>
                  Public Property FileContents As Byte()


                  How I encountered it: It was while reading an 11-column table of about 3000 rows. One of the columns was actually an NCLOB (so apparently this is just as susceptible as CLOB), which allowed nulls in the database, and some of its values were empty - it was an optional "Notes" field, after all. It's funny that I didn't get this error on the first or even second row that had an empty Notes field. It didn't error until row 768 finished and it was about to start row 769, according to an int counter variable that started at 0 that I set up and saw after checking how many rows my DataTable had thus far. I found I got the error if I used:



                  DataSet ds = new DataSet();
                  OracleDataAdapter adapter = new OracleDataAdapter(cmd);
                  adapter.Fill(ds);


                  as well if I used:



                  DataTable dt = new DataTable();
                  OracleDataReader dr = cmd.ExecuteReader();
                  dt.Load(dr);


                  or if I used:



                  OracleDataReader dr = cmd.ExecuteReader();
                  if (dr.HasRows)
                  {
                  while (dr.Read())
                  {
                  ....
                  }
                  }


                  where cmd is the OracleCommand, so it made no difference.



                  Resolution


                  The following is basically the code I used to parse through an OracleDataReader values in order to assign them to a DataTable. It's actually not as refined as it could be - I am using it to just return dr[i] to datarow in all cases except when the value is null, and when it is the eleventh column (index = 10, because it starts at 0) and a particular query has been executed so that I know where my NCLOB column is.



                  public static DataTable GetDataTableManually(string query)
                  {
                  OracleConnection conn = null;
                  try
                  {
                  string connString = ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString;
                  conn = new OracleConnection(connString);
                  OracleCommand cmd = new OracleCommand(query, conn);
                  conn.Open();
                  OracleDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                  DataTable dtSchema = dr.GetSchemaTable();
                  DataTable dt = new DataTable();

                  List<DataColumn> listCols = new List<DataColumn>();
                  List<DataColumn> listTypes = new List<DataColumn>();

                  if (dtSchema != null)
                  {
                  foreach (DataRow drow in dtSchema.Rows)
                  {
                  string columnName = System.Convert.ToString(drow["ColumnName"]);
                  DataColumn column = new DataColumn(columnName, (Type)(drow["DataType"]));
                  listCols.Add(column);
                  listTypes.Add(drow["DataType"].ToString()); // necessary in order to record nulls
                  dt.Columns.Add(column);
                  }
                  }

                  // Read rows from DataReader and populate the DataTable
                  if (dr.HasRows)
                  {
                  int rowCount = 0;
                  while (dr.Read())
                  {
                  string fieldType = String.Empty;
                  DataRow dataRow = dt.NewRow();

                  for (int i = 0; i < dr.FieldCount; i++)
                  {
                  if (!dr.IsDBNull[i])
                  {
                  fieldType = dr.GetFieldType(i).ToString(); // example only, this is the same as listTypes[i], and neither help us distinguish NCLOB from NVARCHAR2 - both will say System.String

                  // This is the magic
                  if (query == "SELECT * FROM Orders" && i == 10)
                  dataRow[((DataColumn)listCols[i])] = dr.GetOracleClob(i); // <-- our new check!!!!
                  // Found if you have null Decimal fields, this is
                  // also needed, and GetOracleDecimal and GetDecimal
                  // will not help you - only GetFloat does
                  else if (listTypes[i] == "System.Decimal")
                  dataRow[((DataColumn)listCols[i])] = dr.GetFloat(i);
                  else
                  dataRow[((DataColumn)listCols[i])] = dr[i];
                  }
                  else // value was null; we can't always assign dr[i] if DBNull, such as when it is a number or decimal field
                  {
                  byte nullArray = new byte[0];
                  switch (listTypes[i])
                  {
                  case "System.String": // includes NVARCHAR2, CLOB, NCLOB, etc.
                  dataRow[((DataColumn)listCols[i])] = String.Empty;
                  break;
                  case "System.Decimal":
                  case "System.Int16": // Boolean
                  case "System.Int32": // Number
                  dataRow[((DataColumn)listCols[i])] = 0;
                  break;
                  case "System.DateTime":
                  dataRow[((DataColumn)listCols[i])] = DBNull.Value;
                  break;
                  case "System.Byte": // Blob
                  dataRow[((DataColumn)listCols[i])] = nullArray;
                  break;
                  default:
                  dataRow[((DataColumn)listCols[i])] = String.Empty;
                  break;
                  }
                  }
                  }
                  dt.Rows.Add(dataRow);
                  }
                  ds.Tables.Add(dt);
                  }

                  }
                  catch (Exception ex)
                  {
                  // handle error
                  }
                  finally
                  {
                  conn.Close();
                  }

                  // After everything is closed
                  if (ds.Tables.Count > 0)
                  return ds.Tables[0]; // there should only be one table if we got results
                  else
                  return null;

                  }


                  In the same way that I have it assigning specific types of null based on the column type found in the schema table loop, you could add the conditions to the "not null" side of the if...then and do various GetOracle... statements there. I found it was only necessary for this NCLOB instance, though.



                  To give credit where credit is due, the original codebase is based on the answer given by sarathkumar at Populate data table from data reader .






                  share|improve this answer




























                    1














                    I spent a lot of time trying to decipher this and found bits of this and that here and there on the internet, but no where had everything in one place, so I'd like to post what I've learned, and how I resolved it, which is much like Ragowit's answer, but I've got the C# code for it.



                    Background

                    The error: So I had this error on my while (dr.Read()) line:



                    Value cannot be null. rnParmeter name: byteArray


                    I ran into very little on the internet about this, except that it was an error with the CLOB field when it was null, and was supposedly fixed in the latest ODAC release, according to this: https://community.oracle.com/thread/3944924



                    My take on this -- NOT TRUE! It hasn't been updated since October 5, 2015 (http://www.oracle.com/technetwork/topics/dotnet/utilsoft-086879.html), and the 12c package I'm using was downloaded in April 2016.



                    Full stack trace by someone else with the error that pretty much mirrored mine: http://pastebin.com/24AfFDnq



                    Value cannot be null.
                    Parameter name: byteArray

                    at System.BitConverter.ToString(Byte value, Int32 startIndex, Int32 length)
                    at OracleInternal.TTC.TTCLob.GetLobIdString(Byte lobLocator)
                    at OracleInternal.ServiceObjects.OracleDataReaderImpl.CollectTempLOBsToBeFreed(Int32 rowNumber)
                    at Oracle.ManagedDataAccess.Client.OracleDataReader.ProcessAnyTempLOBs(Int32 rowNumber)
                    at Oracle.ManagedDataAccess.Client.OracleDataReader.Read()
                    at System.Data.Entity.Core.Common.Internal.Materialization.Shaper`1.StoreRead()

                    'Mapped to Oracle CLOB Column'
                    <Column("LARGEFIELD")>
                    Public Property LargeField As String

                    'Mapped to Oracle BLOB Column'
                    <Column("IMAGE")>
                    Public Property FileContents As Byte()


                    How I encountered it: It was while reading an 11-column table of about 3000 rows. One of the columns was actually an NCLOB (so apparently this is just as susceptible as CLOB), which allowed nulls in the database, and some of its values were empty - it was an optional "Notes" field, after all. It's funny that I didn't get this error on the first or even second row that had an empty Notes field. It didn't error until row 768 finished and it was about to start row 769, according to an int counter variable that started at 0 that I set up and saw after checking how many rows my DataTable had thus far. I found I got the error if I used:



                    DataSet ds = new DataSet();
                    OracleDataAdapter adapter = new OracleDataAdapter(cmd);
                    adapter.Fill(ds);


                    as well if I used:



                    DataTable dt = new DataTable();
                    OracleDataReader dr = cmd.ExecuteReader();
                    dt.Load(dr);


                    or if I used:



                    OracleDataReader dr = cmd.ExecuteReader();
                    if (dr.HasRows)
                    {
                    while (dr.Read())
                    {
                    ....
                    }
                    }


                    where cmd is the OracleCommand, so it made no difference.



                    Resolution


                    The following is basically the code I used to parse through an OracleDataReader values in order to assign them to a DataTable. It's actually not as refined as it could be - I am using it to just return dr[i] to datarow in all cases except when the value is null, and when it is the eleventh column (index = 10, because it starts at 0) and a particular query has been executed so that I know where my NCLOB column is.



                    public static DataTable GetDataTableManually(string query)
                    {
                    OracleConnection conn = null;
                    try
                    {
                    string connString = ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString;
                    conn = new OracleConnection(connString);
                    OracleCommand cmd = new OracleCommand(query, conn);
                    conn.Open();
                    OracleDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                    DataTable dtSchema = dr.GetSchemaTable();
                    DataTable dt = new DataTable();

                    List<DataColumn> listCols = new List<DataColumn>();
                    List<DataColumn> listTypes = new List<DataColumn>();

                    if (dtSchema != null)
                    {
                    foreach (DataRow drow in dtSchema.Rows)
                    {
                    string columnName = System.Convert.ToString(drow["ColumnName"]);
                    DataColumn column = new DataColumn(columnName, (Type)(drow["DataType"]));
                    listCols.Add(column);
                    listTypes.Add(drow["DataType"].ToString()); // necessary in order to record nulls
                    dt.Columns.Add(column);
                    }
                    }

                    // Read rows from DataReader and populate the DataTable
                    if (dr.HasRows)
                    {
                    int rowCount = 0;
                    while (dr.Read())
                    {
                    string fieldType = String.Empty;
                    DataRow dataRow = dt.NewRow();

                    for (int i = 0; i < dr.FieldCount; i++)
                    {
                    if (!dr.IsDBNull[i])
                    {
                    fieldType = dr.GetFieldType(i).ToString(); // example only, this is the same as listTypes[i], and neither help us distinguish NCLOB from NVARCHAR2 - both will say System.String

                    // This is the magic
                    if (query == "SELECT * FROM Orders" && i == 10)
                    dataRow[((DataColumn)listCols[i])] = dr.GetOracleClob(i); // <-- our new check!!!!
                    // Found if you have null Decimal fields, this is
                    // also needed, and GetOracleDecimal and GetDecimal
                    // will not help you - only GetFloat does
                    else if (listTypes[i] == "System.Decimal")
                    dataRow[((DataColumn)listCols[i])] = dr.GetFloat(i);
                    else
                    dataRow[((DataColumn)listCols[i])] = dr[i];
                    }
                    else // value was null; we can't always assign dr[i] if DBNull, such as when it is a number or decimal field
                    {
                    byte nullArray = new byte[0];
                    switch (listTypes[i])
                    {
                    case "System.String": // includes NVARCHAR2, CLOB, NCLOB, etc.
                    dataRow[((DataColumn)listCols[i])] = String.Empty;
                    break;
                    case "System.Decimal":
                    case "System.Int16": // Boolean
                    case "System.Int32": // Number
                    dataRow[((DataColumn)listCols[i])] = 0;
                    break;
                    case "System.DateTime":
                    dataRow[((DataColumn)listCols[i])] = DBNull.Value;
                    break;
                    case "System.Byte": // Blob
                    dataRow[((DataColumn)listCols[i])] = nullArray;
                    break;
                    default:
                    dataRow[((DataColumn)listCols[i])] = String.Empty;
                    break;
                    }
                    }
                    }
                    dt.Rows.Add(dataRow);
                    }
                    ds.Tables.Add(dt);
                    }

                    }
                    catch (Exception ex)
                    {
                    // handle error
                    }
                    finally
                    {
                    conn.Close();
                    }

                    // After everything is closed
                    if (ds.Tables.Count > 0)
                    return ds.Tables[0]; // there should only be one table if we got results
                    else
                    return null;

                    }


                    In the same way that I have it assigning specific types of null based on the column type found in the schema table loop, you could add the conditions to the "not null" side of the if...then and do various GetOracle... statements there. I found it was only necessary for this NCLOB instance, though.



                    To give credit where credit is due, the original codebase is based on the answer given by sarathkumar at Populate data table from data reader .






                    share|improve this answer


























                      1












                      1








                      1






                      I spent a lot of time trying to decipher this and found bits of this and that here and there on the internet, but no where had everything in one place, so I'd like to post what I've learned, and how I resolved it, which is much like Ragowit's answer, but I've got the C# code for it.



                      Background

                      The error: So I had this error on my while (dr.Read()) line:



                      Value cannot be null. rnParmeter name: byteArray


                      I ran into very little on the internet about this, except that it was an error with the CLOB field when it was null, and was supposedly fixed in the latest ODAC release, according to this: https://community.oracle.com/thread/3944924



                      My take on this -- NOT TRUE! It hasn't been updated since October 5, 2015 (http://www.oracle.com/technetwork/topics/dotnet/utilsoft-086879.html), and the 12c package I'm using was downloaded in April 2016.



                      Full stack trace by someone else with the error that pretty much mirrored mine: http://pastebin.com/24AfFDnq



                      Value cannot be null.
                      Parameter name: byteArray

                      at System.BitConverter.ToString(Byte value, Int32 startIndex, Int32 length)
                      at OracleInternal.TTC.TTCLob.GetLobIdString(Byte lobLocator)
                      at OracleInternal.ServiceObjects.OracleDataReaderImpl.CollectTempLOBsToBeFreed(Int32 rowNumber)
                      at Oracle.ManagedDataAccess.Client.OracleDataReader.ProcessAnyTempLOBs(Int32 rowNumber)
                      at Oracle.ManagedDataAccess.Client.OracleDataReader.Read()
                      at System.Data.Entity.Core.Common.Internal.Materialization.Shaper`1.StoreRead()

                      'Mapped to Oracle CLOB Column'
                      <Column("LARGEFIELD")>
                      Public Property LargeField As String

                      'Mapped to Oracle BLOB Column'
                      <Column("IMAGE")>
                      Public Property FileContents As Byte()


                      How I encountered it: It was while reading an 11-column table of about 3000 rows. One of the columns was actually an NCLOB (so apparently this is just as susceptible as CLOB), which allowed nulls in the database, and some of its values were empty - it was an optional "Notes" field, after all. It's funny that I didn't get this error on the first or even second row that had an empty Notes field. It didn't error until row 768 finished and it was about to start row 769, according to an int counter variable that started at 0 that I set up and saw after checking how many rows my DataTable had thus far. I found I got the error if I used:



                      DataSet ds = new DataSet();
                      OracleDataAdapter adapter = new OracleDataAdapter(cmd);
                      adapter.Fill(ds);


                      as well if I used:



                      DataTable dt = new DataTable();
                      OracleDataReader dr = cmd.ExecuteReader();
                      dt.Load(dr);


                      or if I used:



                      OracleDataReader dr = cmd.ExecuteReader();
                      if (dr.HasRows)
                      {
                      while (dr.Read())
                      {
                      ....
                      }
                      }


                      where cmd is the OracleCommand, so it made no difference.



                      Resolution


                      The following is basically the code I used to parse through an OracleDataReader values in order to assign them to a DataTable. It's actually not as refined as it could be - I am using it to just return dr[i] to datarow in all cases except when the value is null, and when it is the eleventh column (index = 10, because it starts at 0) and a particular query has been executed so that I know where my NCLOB column is.



                      public static DataTable GetDataTableManually(string query)
                      {
                      OracleConnection conn = null;
                      try
                      {
                      string connString = ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString;
                      conn = new OracleConnection(connString);
                      OracleCommand cmd = new OracleCommand(query, conn);
                      conn.Open();
                      OracleDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                      DataTable dtSchema = dr.GetSchemaTable();
                      DataTable dt = new DataTable();

                      List<DataColumn> listCols = new List<DataColumn>();
                      List<DataColumn> listTypes = new List<DataColumn>();

                      if (dtSchema != null)
                      {
                      foreach (DataRow drow in dtSchema.Rows)
                      {
                      string columnName = System.Convert.ToString(drow["ColumnName"]);
                      DataColumn column = new DataColumn(columnName, (Type)(drow["DataType"]));
                      listCols.Add(column);
                      listTypes.Add(drow["DataType"].ToString()); // necessary in order to record nulls
                      dt.Columns.Add(column);
                      }
                      }

                      // Read rows from DataReader and populate the DataTable
                      if (dr.HasRows)
                      {
                      int rowCount = 0;
                      while (dr.Read())
                      {
                      string fieldType = String.Empty;
                      DataRow dataRow = dt.NewRow();

                      for (int i = 0; i < dr.FieldCount; i++)
                      {
                      if (!dr.IsDBNull[i])
                      {
                      fieldType = dr.GetFieldType(i).ToString(); // example only, this is the same as listTypes[i], and neither help us distinguish NCLOB from NVARCHAR2 - both will say System.String

                      // This is the magic
                      if (query == "SELECT * FROM Orders" && i == 10)
                      dataRow[((DataColumn)listCols[i])] = dr.GetOracleClob(i); // <-- our new check!!!!
                      // Found if you have null Decimal fields, this is
                      // also needed, and GetOracleDecimal and GetDecimal
                      // will not help you - only GetFloat does
                      else if (listTypes[i] == "System.Decimal")
                      dataRow[((DataColumn)listCols[i])] = dr.GetFloat(i);
                      else
                      dataRow[((DataColumn)listCols[i])] = dr[i];
                      }
                      else // value was null; we can't always assign dr[i] if DBNull, such as when it is a number or decimal field
                      {
                      byte nullArray = new byte[0];
                      switch (listTypes[i])
                      {
                      case "System.String": // includes NVARCHAR2, CLOB, NCLOB, etc.
                      dataRow[((DataColumn)listCols[i])] = String.Empty;
                      break;
                      case "System.Decimal":
                      case "System.Int16": // Boolean
                      case "System.Int32": // Number
                      dataRow[((DataColumn)listCols[i])] = 0;
                      break;
                      case "System.DateTime":
                      dataRow[((DataColumn)listCols[i])] = DBNull.Value;
                      break;
                      case "System.Byte": // Blob
                      dataRow[((DataColumn)listCols[i])] = nullArray;
                      break;
                      default:
                      dataRow[((DataColumn)listCols[i])] = String.Empty;
                      break;
                      }
                      }
                      }
                      dt.Rows.Add(dataRow);
                      }
                      ds.Tables.Add(dt);
                      }

                      }
                      catch (Exception ex)
                      {
                      // handle error
                      }
                      finally
                      {
                      conn.Close();
                      }

                      // After everything is closed
                      if (ds.Tables.Count > 0)
                      return ds.Tables[0]; // there should only be one table if we got results
                      else
                      return null;

                      }


                      In the same way that I have it assigning specific types of null based on the column type found in the schema table loop, you could add the conditions to the "not null" side of the if...then and do various GetOracle... statements there. I found it was only necessary for this NCLOB instance, though.



                      To give credit where credit is due, the original codebase is based on the answer given by sarathkumar at Populate data table from data reader .






                      share|improve this answer














                      I spent a lot of time trying to decipher this and found bits of this and that here and there on the internet, but no where had everything in one place, so I'd like to post what I've learned, and how I resolved it, which is much like Ragowit's answer, but I've got the C# code for it.



                      Background

                      The error: So I had this error on my while (dr.Read()) line:



                      Value cannot be null. rnParmeter name: byteArray


                      I ran into very little on the internet about this, except that it was an error with the CLOB field when it was null, and was supposedly fixed in the latest ODAC release, according to this: https://community.oracle.com/thread/3944924



                      My take on this -- NOT TRUE! It hasn't been updated since October 5, 2015 (http://www.oracle.com/technetwork/topics/dotnet/utilsoft-086879.html), and the 12c package I'm using was downloaded in April 2016.



                      Full stack trace by someone else with the error that pretty much mirrored mine: http://pastebin.com/24AfFDnq



                      Value cannot be null.
                      Parameter name: byteArray

                      at System.BitConverter.ToString(Byte value, Int32 startIndex, Int32 length)
                      at OracleInternal.TTC.TTCLob.GetLobIdString(Byte lobLocator)
                      at OracleInternal.ServiceObjects.OracleDataReaderImpl.CollectTempLOBsToBeFreed(Int32 rowNumber)
                      at Oracle.ManagedDataAccess.Client.OracleDataReader.ProcessAnyTempLOBs(Int32 rowNumber)
                      at Oracle.ManagedDataAccess.Client.OracleDataReader.Read()
                      at System.Data.Entity.Core.Common.Internal.Materialization.Shaper`1.StoreRead()

                      'Mapped to Oracle CLOB Column'
                      <Column("LARGEFIELD")>
                      Public Property LargeField As String

                      'Mapped to Oracle BLOB Column'
                      <Column("IMAGE")>
                      Public Property FileContents As Byte()


                      How I encountered it: It was while reading an 11-column table of about 3000 rows. One of the columns was actually an NCLOB (so apparently this is just as susceptible as CLOB), which allowed nulls in the database, and some of its values were empty - it was an optional "Notes" field, after all. It's funny that I didn't get this error on the first or even second row that had an empty Notes field. It didn't error until row 768 finished and it was about to start row 769, according to an int counter variable that started at 0 that I set up and saw after checking how many rows my DataTable had thus far. I found I got the error if I used:



                      DataSet ds = new DataSet();
                      OracleDataAdapter adapter = new OracleDataAdapter(cmd);
                      adapter.Fill(ds);


                      as well if I used:



                      DataTable dt = new DataTable();
                      OracleDataReader dr = cmd.ExecuteReader();
                      dt.Load(dr);


                      or if I used:



                      OracleDataReader dr = cmd.ExecuteReader();
                      if (dr.HasRows)
                      {
                      while (dr.Read())
                      {
                      ....
                      }
                      }


                      where cmd is the OracleCommand, so it made no difference.



                      Resolution


                      The following is basically the code I used to parse through an OracleDataReader values in order to assign them to a DataTable. It's actually not as refined as it could be - I am using it to just return dr[i] to datarow in all cases except when the value is null, and when it is the eleventh column (index = 10, because it starts at 0) and a particular query has been executed so that I know where my NCLOB column is.



                      public static DataTable GetDataTableManually(string query)
                      {
                      OracleConnection conn = null;
                      try
                      {
                      string connString = ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString;
                      conn = new OracleConnection(connString);
                      OracleCommand cmd = new OracleCommand(query, conn);
                      conn.Open();
                      OracleDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                      DataTable dtSchema = dr.GetSchemaTable();
                      DataTable dt = new DataTable();

                      List<DataColumn> listCols = new List<DataColumn>();
                      List<DataColumn> listTypes = new List<DataColumn>();

                      if (dtSchema != null)
                      {
                      foreach (DataRow drow in dtSchema.Rows)
                      {
                      string columnName = System.Convert.ToString(drow["ColumnName"]);
                      DataColumn column = new DataColumn(columnName, (Type)(drow["DataType"]));
                      listCols.Add(column);
                      listTypes.Add(drow["DataType"].ToString()); // necessary in order to record nulls
                      dt.Columns.Add(column);
                      }
                      }

                      // Read rows from DataReader and populate the DataTable
                      if (dr.HasRows)
                      {
                      int rowCount = 0;
                      while (dr.Read())
                      {
                      string fieldType = String.Empty;
                      DataRow dataRow = dt.NewRow();

                      for (int i = 0; i < dr.FieldCount; i++)
                      {
                      if (!dr.IsDBNull[i])
                      {
                      fieldType = dr.GetFieldType(i).ToString(); // example only, this is the same as listTypes[i], and neither help us distinguish NCLOB from NVARCHAR2 - both will say System.String

                      // This is the magic
                      if (query == "SELECT * FROM Orders" && i == 10)
                      dataRow[((DataColumn)listCols[i])] = dr.GetOracleClob(i); // <-- our new check!!!!
                      // Found if you have null Decimal fields, this is
                      // also needed, and GetOracleDecimal and GetDecimal
                      // will not help you - only GetFloat does
                      else if (listTypes[i] == "System.Decimal")
                      dataRow[((DataColumn)listCols[i])] = dr.GetFloat(i);
                      else
                      dataRow[((DataColumn)listCols[i])] = dr[i];
                      }
                      else // value was null; we can't always assign dr[i] if DBNull, such as when it is a number or decimal field
                      {
                      byte nullArray = new byte[0];
                      switch (listTypes[i])
                      {
                      case "System.String": // includes NVARCHAR2, CLOB, NCLOB, etc.
                      dataRow[((DataColumn)listCols[i])] = String.Empty;
                      break;
                      case "System.Decimal":
                      case "System.Int16": // Boolean
                      case "System.Int32": // Number
                      dataRow[((DataColumn)listCols[i])] = 0;
                      break;
                      case "System.DateTime":
                      dataRow[((DataColumn)listCols[i])] = DBNull.Value;
                      break;
                      case "System.Byte": // Blob
                      dataRow[((DataColumn)listCols[i])] = nullArray;
                      break;
                      default:
                      dataRow[((DataColumn)listCols[i])] = String.Empty;
                      break;
                      }
                      }
                      }
                      dt.Rows.Add(dataRow);
                      }
                      ds.Tables.Add(dt);
                      }

                      }
                      catch (Exception ex)
                      {
                      // handle error
                      }
                      finally
                      {
                      conn.Close();
                      }

                      // After everything is closed
                      if (ds.Tables.Count > 0)
                      return ds.Tables[0]; // there should only be one table if we got results
                      else
                      return null;

                      }


                      In the same way that I have it assigning specific types of null based on the column type found in the schema table loop, you could add the conditions to the "not null" side of the if...then and do various GetOracle... statements there. I found it was only necessary for this NCLOB instance, though.



                      To give credit where credit is due, the original codebase is based on the answer given by sarathkumar at Populate data table from data reader .







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Nov 20 at 16:20

























                      answered Nov 18 '16 at 22:37









                      vapcguy

                      3,0402528




                      3,0402528























                          0














                          For me it was simple! I had this error with odac v 4.121.1.0. I have just updated Oracle.ManagedDataAccess to 4.121.2.0 with Nuget and now it is working.



                          Have you have tried to uninstall and reinstall Oracle.ManagedDataAccess with Nugget?






                          share|improve this answer




























                            0














                            For me it was simple! I had this error with odac v 4.121.1.0. I have just updated Oracle.ManagedDataAccess to 4.121.2.0 with Nuget and now it is working.



                            Have you have tried to uninstall and reinstall Oracle.ManagedDataAccess with Nugget?






                            share|improve this answer


























                              0












                              0








                              0






                              For me it was simple! I had this error with odac v 4.121.1.0. I have just updated Oracle.ManagedDataAccess to 4.121.2.0 with Nuget and now it is working.



                              Have you have tried to uninstall and reinstall Oracle.ManagedDataAccess with Nugget?






                              share|improve this answer














                              For me it was simple! I had this error with odac v 4.121.1.0. I have just updated Oracle.ManagedDataAccess to 4.121.2.0 with Nuget and now it is working.



                              Have you have tried to uninstall and reinstall Oracle.ManagedDataAccess with Nugget?







                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Apr 14 '16 at 15:15









                              Mogsdad

                              32.9k1186191




                              32.9k1186191










                              answered Apr 14 '16 at 14:36









                              toregua

                              537519




                              537519























                                  0














                                  After installation of Oracle12 client we ran into the same problem.
                                  In machine.config (C:WindowsMicrosoft.NETFrameworkv4.0.30319Config) I removed all entries with Oracle.ManagedDataAccess.
                                  In directory C:WindowsMicrosoft.NETassemblyGAC_MSIL I removed both Oracle.ManagedDataAccess and Policy.4.121.Oracle.ManagedDataAccess.
                                  Then my C# program started working as usually, using the Oracle.ManagedDataAccess dll in it's own directory.






                                  share|improve this answer


























                                    0














                                    After installation of Oracle12 client we ran into the same problem.
                                    In machine.config (C:WindowsMicrosoft.NETFrameworkv4.0.30319Config) I removed all entries with Oracle.ManagedDataAccess.
                                    In directory C:WindowsMicrosoft.NETassemblyGAC_MSIL I removed both Oracle.ManagedDataAccess and Policy.4.121.Oracle.ManagedDataAccess.
                                    Then my C# program started working as usually, using the Oracle.ManagedDataAccess dll in it's own directory.






                                    share|improve this answer
























                                      0












                                      0








                                      0






                                      After installation of Oracle12 client we ran into the same problem.
                                      In machine.config (C:WindowsMicrosoft.NETFrameworkv4.0.30319Config) I removed all entries with Oracle.ManagedDataAccess.
                                      In directory C:WindowsMicrosoft.NETassemblyGAC_MSIL I removed both Oracle.ManagedDataAccess and Policy.4.121.Oracle.ManagedDataAccess.
                                      Then my C# program started working as usually, using the Oracle.ManagedDataAccess dll in it's own directory.






                                      share|improve this answer












                                      After installation of Oracle12 client we ran into the same problem.
                                      In machine.config (C:WindowsMicrosoft.NETFrameworkv4.0.30319Config) I removed all entries with Oracle.ManagedDataAccess.
                                      In directory C:WindowsMicrosoft.NETassemblyGAC_MSIL I removed both Oracle.ManagedDataAccess and Policy.4.121.Oracle.ManagedDataAccess.
                                      Then my C# program started working as usually, using the Oracle.ManagedDataAccess dll in it's own directory.







                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Dec 28 '16 at 14:05









                                      CasaSpider

                                      1




                                      1























                                          0














                                          upgrade Oracle.ManagedDataAccess.dll to version 4.122.1.0 solved.
                                          If you are using vs 2017, we can update via NuGet.



                                          enter image description here






                                          share|improve this answer





















                                          • Error appears again even with latest version. Solved by add nvl() to clob column in oracle procedure.
                                            – Song
                                            Jun 27 at 2:49
















                                          0














                                          upgrade Oracle.ManagedDataAccess.dll to version 4.122.1.0 solved.
                                          If you are using vs 2017, we can update via NuGet.



                                          enter image description here






                                          share|improve this answer





















                                          • Error appears again even with latest version. Solved by add nvl() to clob column in oracle procedure.
                                            – Song
                                            Jun 27 at 2:49














                                          0












                                          0








                                          0






                                          upgrade Oracle.ManagedDataAccess.dll to version 4.122.1.0 solved.
                                          If you are using vs 2017, we can update via NuGet.



                                          enter image description here






                                          share|improve this answer












                                          upgrade Oracle.ManagedDataAccess.dll to version 4.122.1.0 solved.
                                          If you are using vs 2017, we can update via NuGet.



                                          enter image description here







                                          share|improve this answer












                                          share|improve this answer



                                          share|improve this answer










                                          answered May 21 at 13:03









                                          Song

                                          9718




                                          9718












                                          • Error appears again even with latest version. Solved by add nvl() to clob column in oracle procedure.
                                            – Song
                                            Jun 27 at 2:49


















                                          • Error appears again even with latest version. Solved by add nvl() to clob column in oracle procedure.
                                            – Song
                                            Jun 27 at 2:49
















                                          Error appears again even with latest version. Solved by add nvl() to clob column in oracle procedure.
                                          – Song
                                          Jun 27 at 2:49




                                          Error appears again even with latest version. Solved by add nvl() to clob column in oracle procedure.
                                          – Song
                                          Jun 27 at 2:49


















                                          draft saved

                                          draft discarded




















































                                          Thanks for contributing an answer to Stack Overflow!


                                          • Please be sure to answer the question. Provide details and share your research!

                                          But avoid



                                          • Asking for help, clarification, or responding to other answers.

                                          • Making statements based on opinion; back them up with references or personal experience.


                                          To learn more, see our tips on writing great answers.





                                          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                          Please pay close attention to the following guidance:


                                          • Please be sure to answer the question. Provide details and share your research!

                                          But avoid



                                          • Asking for help, clarification, or responding to other answers.

                                          • Making statements based on opinion; back them up with references or personal experience.


                                          To learn more, see our tips on writing great answers.




                                          draft saved


                                          draft discarded














                                          StackExchange.ready(
                                          function () {
                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f28593520%2fef-odp-net-clob-value-cannot-be-null-parameter-name-bytearray%23new-answer', 'question_page');
                                          }
                                          );

                                          Post as a guest















                                          Required, but never shown





















































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown

































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown







                                          Popular posts from this blog

                                          Costa Masnaga

                                          Fotorealismo

                                          Sidney Franklin