系统内存不足

时间:2016-11-21 14:02:28

标签: c# azure memory out-of-memory

我正在尝试将一些数据从azure db同步到本地数据库。我通常让它适用于一个特定的数据集但是当我转移到更大的更强大的数据集时,我得到一个内部服务器错误,我已经解决了系统内存不足。

System.IO.MemoryStream.set_Capacity(Int32 value) ↵在System.IO.MemoryStream.EnsureCapacity(Int32值) ↵

enter image description here 服务器的详细错误代码 - 详细错误信息:

模块    ManagedPipelineHandler

通知    ExecuteRequestHandler

处理程序    System.Web.Http.WebHost.HttpControllerHandler

错误代码    0x00000000

这是我的代码。它在成功状态代码块中失败,然后给出了内部错误。我一直在看这几天,看不出任何与众不同的东西,为什么一个团队会工作而另一个团队不会工作。任何建议,将不胜感激。谢谢

            using (var handler = new HttpClientHandler())
        {
            handler.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
            using (var client = new HttpClient(handler, false))
            {

                client.BaseAddress = new Uri(syncServerURL);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip"));
                client.DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue("deflate"));
                client.Timeout = new TimeSpan(0, 10, 0);

                int syncGroups = 0;
                int index = 1;
                foreach (var gt in SyncGroup.GroupTypes)
                {
                    syncGroups = SyncGroup.GroupTypes.Count;
                    System.Diagnostics.Trace.TraceInformation($"{System.DateTime.UtcNow.ToLongTimeString()} {index} of {syncGroups} starting to process ");
                    try
                    {
                        var syncGroup = SyncGroup.CreateSyncGroup(gt, syncStore.Id, db);
                        var syncGroupWrapper = SyncGroupWrapper.GetSyncGroupWrapper(syncGroup);

                        System.Diagnostics.Trace.TraceInformation($"{System.DateTime.UtcNow.ToLongTimeString()} - Sending {gt} data to azure.");

                        var sgw = JsonConvert.SerializeObject(syncGroupWrapper, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All });
                        var content = new StringContent(sgw.ToString(), System.Text.Encoding.UTF8, "application/json");
                        var response = await client.PostAsync($"api/sync/ss", content); 

                        if (!response.IsSuccessStatusCode)
                        {
                            System.Diagnostics.Trace.TraceError($"{response.StatusCode} {response.ReasonPhrase}");
                            System.Diagnostics.Trace.TraceError($"{response.StatusCode} {response.RequestMessage}");
                            return InternalServerError(new Exception(response.ReasonPhrase));
                        }

                        var json = response.Content.ReadAsStringAsync().Result;
                        System.Diagnostics.Trace.TraceInformation($"{System.DateTime.UtcNow.ToLongTimeString()} - Received {gt} data back from azure.");
                        syncGroupWrapper = JsonConvert.DeserializeObject(json, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All }) as SyncGroupWrapper;
                        if (syncGroupWrapper == null) return InternalServerError();

                        await syncGroupWrapper.Group.SaveGroup(db);
                    }
                    catch (Exception ex)
                    {
                        while (ex.InnerException != null)
                        {
                            ex = ex.InnerException;
                        }

                        System.Diagnostics.Trace.TraceError(ex.Message);
                    }
                    index++;
                }

                return Ok();
            }

0 个答案:

没有答案