ado.net查询突然停止处理我的查询

koaltpgm  于 2021-07-26  发布在  Java
关注(0)|答案(1)|浏览(323)

我正在asp.net应用程序中使用ado.net。突然,我的询问停止了。这是原始查询:

using (var sqlConnection = new SqlConnection(this.connection))
{
    var sql = @"select *
                From Contacts.Departments a
                Left Outer Join Contacts.ContactMapping b on a.DepartmentID = b.DepartmentID
                Left Outer Join Contacts.Contacts c on b.ContactID = c.ContactID
                Left Outer Join Contacts.Divisions d on b.DivisionID = d.DivisionID
                Left Outer Join Contacts.Emails e on b.EmailID = e.EmailID
                Left Outer Join Contacts.Phones f on b.PhoneID = f.PhoneID
                Where a.DepartmentID = @DepartmentID and c.IsDeleted = 0 and b.IsDeleted = 0 and f.PhoneTypeID = 1;";
    ...

    ...
}

当它执行时,我得到一个错误
执行超时已过期。操作完成前已过超时时间,或者服务器没有响应。
结果应该只返回45行,所以不是很大。当我在SQLServerManagementStudio中运行查询时,这不是问题,我得到了45行。
但在我的应用程序中,如果我在语句中加一个top,那么它就起作用了:

var sql = @"select top 1000 *
            From Contacts.Departments a
            Left Outer Join Contacts.ContactMapping b on a.DepartmentID = b.DepartmentID
            Left Outer Join Contacts.Contacts c on b.ContactID = c.ContactID
            Left Outer Join Contacts.Divisions d on b.DivisionID = d.DivisionID
            Left Outer Join Contacts.Emails e on b.EmailID = e.EmailID
            Left Outer Join Contacts.Phones f on b.PhoneID = f.PhoneID
            Where a.DepartmentID = @DepartmentID and c.IsDeleted = 0 and b.IsDeleted = 0 and f.PhoneTypeID = 1;";

或者如果我取出参数化查询,直接在字符串中添加值:

var sql = $@"select *
            From Contacts.Departments a
            Left Outer Join Contacts.ContactMapping b on a.DepartmentID = b.DepartmentID
            Left Outer Join Contacts.Contacts c on b.ContactID = c.ContactID
            Left Outer Join Contacts.Divisions d on b.DivisionID = d.DivisionID
            Left Outer Join Contacts.Emails e on b.EmailID = e.EmailID
            Left Outer Join Contacts.Phones f on b.PhoneID = f.PhoneID
            Where a.DepartmentID = {department_id} and c.IsDeleted = 0 and b.IsDeleted = 0 and f.PhoneTypeID = 1;";

这是如此奇怪,因为我没有触及代码,突然它就失败了。当我在我的开发机器上测试时,我可以重新创建上面的错误和解决方案。
我有点不知道该检查什么,因为当我将查询修改为上面两个查询中的一个时,它就工作了。但是,在尝试从SQLServer2016检索数据时,为什么原始的会失败呢

bqjvbblv

bqjvbblv1#

签入连接字符串超时变量
例子
综合安全=sspi;连接超时=30

相关问题