小编Axe*_*xel的帖子

Visual Studio在线单元测试和localDb

我有一个基于Visual Studio Online的解决方案.此解决方案中的所有单元测试都需要一个数据库,我试图让构建使用测试的专用localdb(通过在测试项目中添加一个light mdf文件并使用localdb连接字符串)但是它失败并出现此错误(evrything工作正常)在我的桌面上):

System.Data.SqlClient.SqlException:连接超时已过期.尝试使用登录前握手确认时超时时间已过.这可能是因为登录前握手失败或服务器无法及时响应.尝试连接到此服务器所花费的时间是 - [Pre-Login] initialization = 29460; 握手= 161; ---> System.ComponentModel.Win32Exception:等待操作超时.

编辑

连接字符串是

<add name="TestDb" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=AeroBase;Integrated Security=true;AttachDBFilename=|DataDirectory|\App_Data\AeroBase.mdf" providerName="System.Data.SqlClient" /> 
Run Code Online (Sandbox Code Playgroud)

我首先使用EF6代码,存储库和工作模式单元来访问它.这是DbContext:

public class AeroDataContext : DbContext, IDbContext
{
private Guid DataContextId;
private string _name;
public string Name { get { return _name; } }

public AeroDataContext(string cnxStringName, string cnxString)
    : base(cnxString)
{
    this.Database.Log = delegate(String name)
                        {
                           // Debug.WriteLine(name);
                        };
    _name = cnxStringName;
    this.Configuration.LazyLoadingEnabled = false;
    DataContextId = Guid.NewGuid();
    Debug.WriteLine("AeroDbCreation Id = " + DataContextId.ToString());


} …
Run Code Online (Sandbox Code Playgroud)

localdb azure-devops

9
推荐指数
1
解决办法
3273
查看次数

标签 统计

azure-devops ×1

localdb ×1