3
votes

Without Data Type is CLOB I can easy to read Oracle Table data , but unfortunately I do got a serious problem when some tables have the CLOB of data type , how can I do .

Error Message

{"$id":"1","Message":"An error has occurred.","ExceptionMessage":"The 'ObjectContent1' type failed to serialize the response body for content type 'application/json; charset=utf-8'.","ExceptionType":"System.InvalidOperationException","StackTrace":null,"InnerException":{"$id":"2","$type":"System.Web.Http.HttpError, System.Web.Http","Message":"An error has occurred.","ExceptionMessage":"Exception of type 'System.OutOfMemoryException' was thrown.","ExceptionType":"System.OutOfMemoryException","StackTrace":" at System.String.Concat(String str0, String str1)\r\n at OracleInternal.I18N.Conv.ConvertBytesToString(IList1 bytes, Int32 bytesOffset, Int32 bytesCount, Char[] chars, Boolean bUseReplacementChar)\r\n at OracleInternal.I18N.Conv.ConvertBytesToString(IList1 bytes, Char[] chars, Boolean bUseReplacementChar)\r\n at OracleInternal.ServiceObjects.OracleClobImpl.GetCompleteClobData(Int32 currentRow, Int32 columnIndex, OracleConnectionImpl connImpl, Byte[] lobLocator, DataUnmarshaller dataUnmarshaller, TTCLobAccessor lobAccessor, OracleClobImpl& oraClobImpl)\r\n at Oracle.ManagedDataAccess.Client.OracleDataReader.GetString(Int32 i)\r\n at lambda_method(Closure , Shaper )\r\n at System.Data.Entity.Core.Common.Internal.Materialization.Shaper.HandleEntityAppendOnly[TEntity](Func2 constructEntityDelegate, EntityKey entityKey, EntitySet entitySet)\r\n at lambda_method(Closure , Shaper )\r\n at System.Data.Entity.Core.Common.Internal.Materialization.Coordinator1.ReadNextElement(Shaper shaper)\r\n at System.Data.Entity.Core.Common.Internal.Materialization.Shaper1.SimpleEnumerator.MoveNext()\r\n at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList(JsonWriter writer, IEnumerable values, JsonArrayContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)\r\n at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)\r\n at Newtonsoft.Json.JsonSerializer.Serialize(JsonWriter jsonWriter, Object value)\r\n at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, Encoding effectiveEncoding)\r\n at System.Net.Http.Formatting.JsonMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, Encoding effectiveEncoding)\r\n at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, HttpContent content)\r\n at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStreamAsync(Type type, Object value, Stream writeStream, HttpContent content, TransportContext transportContext, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.GetResult()\r\n at System.Web.Http.WebHost.HttpControllerHandler.d__1b.MoveNext()"}}

PS: Environment
1. Visual Studio 2015
2. ASP.NET MVC WebApi (entity framework)
3. Oracle 11G
4. use VS default Web API project

1
hi did you miss some components , can you check nuget like Entity framework / Oracle etc. that are updated to latest versionWillie Cheng
I have updated all latest stable version in my projecta09375447221

1 Answers

1
votes

"Exception of type 'System.OutOfMemoryException' was thrown."

I guess your CLOB object is too big to be transformed. How big is it? Check your available memory during the program execution. Do you have enough free memory?

Based on this answer on the Oracle Community looks like there are a couple of issues in the .net driver when CLOB is involved; a suggestion I found there is to try parse the CLOB as a generic BLOB and read it as byte[]. Than you can transform the byte[] to string like this

string result = System.Text.Encoding.UTF8.GetString(byteArray);