[英]Artificially create a connection timeout error in .net
我正在使用asp.net MVC框架,並使用EntityFramework連接到數據庫。 有時在連接數據庫時出現超時錯誤。 這些錯誤非常罕見。
System.Data.Entity.Infrastructure.DbUpdateException:
An error occurred while updating the entries. See the inner exception for details. ---> System.Data.UpdateException: An error occurred while updating the entries.
See the inner exception for details. ---> System.Data.SqlClient.SqlException:
Timeout expired. The timeout period elapsed prior to
completion of the operation or the server is not responding.
var myList = new List<MyConnection>();
using (var db = new MyDb())
{
var activeConns = db.Connections
.Where(c => c.Key == tKey)
.Where(c => c.IsActive)
.ToList();
if (activeConns.Count > 0)
{
//Some custom logic
myList.add(conn);
}
return myList;
}
我沒有設置任何連接超時期限。 使用實體框架時是否有最佳實踐?
我如何人為地產生這種缺陷,以便可以測試我們的軟件?
您可能需要使用反射來引發SQL超時異常。 查看本文以獲取幫助: http : //blog.developers.ba/post/2009/03/08/SqlException-class-doesnt-have-public-constructor.aspx
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.