C#Entity Framework超时创建DataTable

时间:2017-10-02 15:37:58

标签: c# entity-framework

VS 2015 EF 6.0

我正在尝试自动化一项可怕的工作:创建一个多表excel工作簿,其中每个工作表是不同查询的结果。首先,如果有一个现有的,自动的方式这样做而不滚动我自己的解决方案,请告诉我。否则:

我为每个查询字符串构建了每表查询的集合,我执行以下操作:

    ...
    "query" passed in as string above
    ...

    DataTable dt;
    using (var db = new MyDbEntities()) {
        db.Database.CommandTimeout = 180;

        try {
            dt = db.DataTable(query);
        } catch (Exception e) {
            throw new Exception("Datatable creation failed: " + e.Message);
        }
    }

    ...
    create spreadsheet-sheet
    ...

我有一个导致异常的查询:Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding

我很确定我在180秒超时到期之前获得超时方式。使用我的手表对其进行计时表明DataTables调用忽略了CommandTimeout。它似乎在大约30秒后超时。

修改

请求了相关查询。它跟随。它是继承的。这很难看。这是一头慢猪。它从远程链接的Oracle DB和几个“本地”DB查询。从SSMS运行时,需要几分钟才能完成,但确实已完成。

    SELECT
           UPPER(LOCAL_CONSUMER_TABLE.machine) AS machine,
           UPPER(LOCAL_CONSUMER_TABLE.personId) AS personId,
           Persons.LastName AS lastName,
           Persons.FirstName AS firstName
    FROM
    (
        SELECT
               GROUP_USER_ACCOUNT.UAC_ITU__ID
        FROM
             ORACLE_LINKED_SERVER..CONSUMER_TABLE.GROUP_USER_ACCOUNT AS GROUP_USER_ACCOUNT
        WHERE GROUP_USER_ACCOUNT.UAC_ITU__ID IN
        (
            SELECT
                   GROUP_USERVIEW.ITU_ITU__ID
            FROM
                 LOCAL_CONSUMER_TABLE.dbo.LoginInfoFinal AS LOCAL_CONSUMER_TABLE
                 INNER JOIN ORACLE_LINKED_SERVER..CONSUMER_TABLE.ITG_USER AS GROUP_USERVIEW
                      ON UPPER(LOCAL_CONSUMER_TABLE.personId) = UPPER(GROUP_USERVIEW.ITU_personId)
        )
            AND GROUP_USER_ACCOUNT.UAC_DATE_REVOKED IS NULL
        GROUP BY
                 GROUP_USER_ACCOUNT.UAC_ITU__ID
        HAVING COUNT(GROUP_USER_ACCOUNT.UAC_ITU__ID) > 1
    ) AS USER_ACCOUNT
    INNER JOIN ORACLE_LINKED_SERVER..CONSUMER_TABLE.ITG_USER AS GROUP_USERVIEW
         ON USER_ACCOUNT.UAC_ITU__ID = GROUP_USERVIEW.ITU_ITU__ID
    INNER JOIN LOCAL_CONSUMER_TABLE.dbo.LoginInfoFinal AS LOCAL_CONSUMER_TABLE
         ON UPPER(LOCAL_CONSUMER_TABLE.personId) = UPPER(GROUP_USERVIEW.ITU_personId)
    INNER JOIN FACILITY.Personnel.Persons AS Persons
         ON UPPER(LOCAL_CONSUMER_TABLE.personId) = UPPER(Persons.personId);

1 个答案:

答案 0 :(得分:0)

正如Chris所说,这是连接超时。