Azure - WebJob timeout when calling stored procedure

时间:2016-07-11 23:16:55

标签: sql-server azure azure-sql-database

I have a webjob that calls a long running stored procedure that keeps timing out. Can anyone help please?

The web job is called using the following code:

    static void Main()
    {
        ApplicationDbContext context = new ApplicationDbContext();

        context.Database.CommandTimeout = 6000;

        context.PopulateJobTypeDescendants();

    }

The method on the context (ApplicationDbContext) is shown below:

    public void PopulateJobTypeDescendants()
    {
        Database.ExecuteSqlCommand("PopulateJobTypeDescendants");
    }

The following exception is raised when the web job is run. We have read that it could be related to the plan/DTUs on the server so we went from S1 -> S3, this still didn't solve the issue and the process bombs out after 45 seconds. The strange thing is that if I connect to azure sql db from SSMS and call the stored procedure it works fine.

[07/11/2016 22:25:02 > e2cf50: ERR ] Unhandled Exception: System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. This failure occurred while attempting to connect to the routing destination. The duration spent while attempting to connect to the original server was - [Pre-Login] initialization=14; handshake=26; [Login] initialization=0; authentication=0; [Post-Login] complete=1; ---> System.ComponentModel.Win32Exception: The wait operation timed out

The connection string is shown below:

<add name="TempsContext" connectionString="Server=tcp:[XXX],1433;Database=temps_testing;User ID=[XXX];Password=[XXX];Trusted_Connection=False;Encrypt=True;Connection Timeout=600;" providerName="System.Data.SqlClient" />

2 个答案:

答案 0 :(得分:1)

这可能是由于EF如何将match (p:Person {person_id: "2851389"})-[d:DIAGNOSED_WITH]->(c:Concept) WITH p.person_id AS person_id, d AS diagnoses ORDER BY d.start_date WITH collect(diagnoses) as ordered_diagnoses, person_id as person_id UNWIND ordered_diagnoses as diagnosis MATCH (:Person {person_id: person_id})-[diagnosis]->(c1:Concept) SET diagnosis.touched = TRUE WITH person_id, c1, diagnosis MATCH (:Person {person_id: person_id})-[d2:DIAGNOSED_WITH {touched: FALSE}]-> (c2:Concept) WHERE d2.start_date >= diagnosis.start_date SET d2.touched = TRUE WITH min(d2.start_date) as min_start_date2, person_id, c1, diagnosis MATCH (:Person {person_id: person_id})-[:DIAGNOSED_WITH {start_date: min_start_date2}]->(c2:Concept) MERGE (c1)-[:NEXT {person_id: person_id, start_date1: diagnosis.start_date, start_date2: min_start_date2}]->(c2) 的值传播到其创建的命令的一些不一致所致,例如:进行数据库初始化或从服务器获取版本控制信息。

应该可以使用命令拦截作为解决方法,例如:

CommandTimeout

我在https://github.com/aspnet/EntityFramework6/issues/24创建了一个错误来跟踪此问题。

答案 1 :(得分:0)

确实,它看起来像是一个性能问题。你能否在mihaelab的micrososft dot com离线回复我的服务器,数据库名称详细信息和异常的完整调用堆栈?

谢谢, 米哈埃拉