1

I have a web server on my domain that I'm trying to use Kerberos delegation to allow access to my SQL Server. They are all Server 2008 R2 servers with IIS 7.5 and SQL 2008 R2 (the DC is also Server 2008 R2).

Everything is working, in that I see transactions being executed on my SQL Server under the user's account. However, the first time I access the site after an extended period of time (30 mins or so) I get the following error thrown by my EF DataContext object:

Exception: The underlying provider failed on Open
at System.Data.EntityClient.EntityConnection.OptenStoreConnectionIf...

    Inner Exception: A network-related or instance-specific error occurred while 
      establishing a connection to SQL Server. The server was not found or was not 
      accessible. Verify that the instance name is correct and that SQL Server is 
      configured to allow remote connections. (provider: Named Pipes Provider, 
      error: 40 - Could not open a connection to SQL Server)

        Inner Inner Exception: The system cannot find the file specified

The error page takes ~20 to 30 seconds to be served. After receiving this error, if I hit refresh in my browser, I get the page with all of the data almost instantly (around 200ms)

What would be causing this initial connection to fail, but all subsequent connections to succeed?

Misc information:

  • EF 6.0
  • IIS 7.5, Windows Auth & APS.NET Impersonation enabled, Extended Protection Off, Kernal-mode auth Off, Providers - Negotiate:Kerberos
  • AppPool uses service account (all SPNs are registered to that account)

If there is any more information that you need, let me know and I'll update this list!

UPDATE:

After doing several network traces, I'm seeing the following pattern:

  1. HTTP Request 1
  2. 6 frames of KerberosV5 traffic
  3. HTTP Response: No SQL Data
  4. HTTP Request 2
  5. 2 frames of KerberosV5 traffic
  6. TDS Prelogin
  7. TDS Response
  8. 2 more frames KerberosV5 traffic (TGS MSSQLSvc request and response)
  9. 6 frames of TDS Traffic (SQL Data)
  10. HTTP Response: Success!!

I'm thinking this is a kerberos issue...

4

1 回答 1

0

我无法真正说出是什么导致了您的问题,但这里有一个关于如何处理它的提示,以防万一您无法找到原因:

EF CodePlex Link 上的连接弹性

关于连接弹性的 MSDN 文章

这是 Entity Framework 6.x 引入的功能。默认情况下,当EF遇到你提出的问题时,它会抛出异常,然后如果你想重试,你必须编写相当混乱的代码并到处复制。

借助 Connection Resiliency,您可以编写最适合您的 DbExecutionStrategy。DbExecutionStrategy 有一个您可以覆盖的方法,它使您能够决定在发生特定异常类型时是否应再次执行查询。对于正在执行的代码和最终用户来说,这只是执行过程中的轻微延迟,不会出现任何错误。

根据我的个人经验,您现在看到的情况可能是由许多因素造成的,包括托管服务提供商的某些设置(如果您不是在本地托管)。我会查看 SQL 日志或事件查看器,看看 SQL 是否由于某种原因进入不可用状态。

于 2014-05-30T04:18:17.290 回答