简体   繁体   English

为什么实体框架超过SQL Express忽略超时?

[英]Why does Entity Framework over SQL Express ignore timeout?

I have following connection string: 我有以下连接字符串:

metadata=res:// /Database.csdl|res:// /Database.ssdl|res://*/Database.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.\\SQLEXPRESS;AttachDbFilename='Database.mdf';Integrated Security=True;User Instance=True;Connection Timeout=300;" metadata = res:// /Database.csdl|res:// /Database.ssdl|res://*/Database.msl;provider=System.Data.SqlClient;provider connection string =“Data Source =。\\ SQLEXPRESS; AttachDbFilename ='Database.mdf'; Integrated Security = True; User Instance = True; Connection Timeout = 300;“

I expect that this connection string can never get timeout (because it is 5 mins). 我希望这个连接字符串永远不会超时(因为它是5分钟)。 However, on a very easy database.table.Count() call to Entity Framework it fails in 10 seconds with "Timeout" exception. 但是,在对Entity Framework的一个非常简单的database.table.Count()调用中,它在10秒内失败并出现“超时”异常。 Why does Entity Framework ignores SQL timeout? 为什么Entity Framework会忽略SQL超时? How to set timeout for Entity Framework? 如何为Entity Framework设置超时?

Connection timeout specifies the amount of time to spend waiting for a connection. 连接超时指定等待连接所花费的时间。 It doesn't affect the amount of time that a query can spend before timing out. 它不会影响查询在超时之前可以花费的时间。

For that, you need to search for a CommandTimeout property on whatever database context class you're using. 为此,您需要在您正在使用的任何数据库上下文类中搜索CommandTimeout属性。

连接超时是尝试连接到不执行查询的数据库服务器时等待的时间

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM