2017-10-17 42 views
0

的SQLExceptions當訂閱ObjectMaterializeEF6 ObjectMaterialized導致測試

((IObjectContextAdapter)context).ObjectContext.ObjectMaterialized += (sender, e) => { /* Note, fails even when the handler is empty */ } 

這部作品在生產代碼罰款。然而,當我加入這個,我得到了測試例外:

Message: System.Data.SqlClient.SqlException : 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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) 

去除單行(ObjectMaterialized + = ..)再次解析它。我一直在調試,但找不到原因。這裏有沒有人碰巧遇到過這個?

回答

0

我是一個doofus ...這是在沒有ConnectionString的測試程序集中,顯然添加此處理程序會導致在實例化DbContext時建立連接。

所以,如果你有這個問題:將連接字符串添加到你的測試項目的App.config。

相關問題