我在 Visual Studio 中有两个项目:我的普通项目和我的测试项目。我选择使用 SpecFlow 进行测试,因此我的测试是基于 UI 的。因此 UI 验证不需要数据库连接。
在某些情况下,我必须为系统设置一些先决条件,例如在项目中填充一些示例数据。我试图将我的项目数据库连接到我的测试项目,但它不起作用。我尝试将连接字符串添加到我的测试项目 app.config 中,如下所示:
<connectionStrings>
<add name="MyConnectionString"
connectionString="Data Source=C:\Users\Martijn\Documents\VS11\Projects\Gastouderuren.nl\testprojectl\App_Data\example.sdf"
providerName="Microsoft.SqlServerCe.Client.4.0" />
</connectionStrings>
当我在代码中使用此连接字符串时,如下所示:
MyContext context = new MyContext(ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString);
context.Product.Count();
当我运行我的测试时,会出现以下错误:
The provider did not return a ProviderManifestToken string. -> This operation requires a connection to the 'master' database. Unable to create a connection to the 'master' database because the original database connection has been opened and credentials have been removed from the connection string. Supply an unopened connection. -> 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)
我已经搜索过解决方案,但找不到任何东西。我怎么解决这个问题?
谢谢!