执行多个进程时出现静态数据表问题

时间:2018-05-30 16:59:51

标签: c# .net linq datatable

我有一个控制台应用程序.exe,它由50多个进程产生,它们将10000条记录通过传入不同的参数插入到数据库中,以便并行运行。

在那个exe中,我使用的是一个静态数据表,它最初存储了一些值,所有进程都使用这个数据表来获取某些值。我现在面临的问题是每周一次或两次,数据表中的值变为空。稍后如果我重新运行exe,我会获得正确的值。

知道这个问题的原因可能是什么?我将app.config中的连接池增加到500.在进程执行50次以上时使用静态数据表是不是很糟糕?

在以下代码中,有时regioncodevalue将变为null,但重新运行后,我将获得值

static DataTable dtZone = all.CreateDataTableFromQuery("O_ZONE", geozonesql, ref ErrorMessage, true);

string regioncodevalue = GetRegionCodeFromGeoZoneCode(geo_zone_code);

private static string GetRegionCodeFromGeoZoneCode(string geo_zone_fromcell)
{
    string region_code = "";

    try
    {
        geo_zone_fromcell = geo_zone_fromcell.Replace(" ", "");

        if (dtZone .Rows.Count > 0)
        {
            var dValue = from row in dtZone .AsEnumerable()
                         where row.Field<string>("GEO_ZONE_CODE") == "" + geo_zone_fromcell + ""
                         select row.Field<string>("REGION_CODE");
            region_code = dValue.First();

            return region_code;
        }
        else
            return "";
    }
    catch (Exception ex)
    {
        log.Error(ex.Message);
        return "";
    }
}

0 个答案:

没有答案