문제

I have a ASP.NET MVC project with integrity test. In test app.config I have a

    <connectionStrings>
        <add name="localhost" connectionString="server=.\SQLEXPRESS;database=repaem;
Integrated Security=SSPI;" providerName="System.Data.SqlClient" />
    </connectionStrings>

I've created Connectionstring alias "localhost" in Sequelizer MSSQL configuration. But when I deploy, tests fails with message "System.Data.SqlClient.SqlException: Cannot open database "repaem" requested by the login. The login failed." Probably, connection string remains the same...

I have tried to create ConnectionFactory manually, as described in http://support.appharbor.com/kb/add-ons/using-sequelizer.

var uriString = ConfigurationManager.AppSettings["SQLSERVER_URI"];
var uri = new Uri(uriString);
SqlConnectionFactory factory = new SqlConnectionFactory(uri.Host, uri.AbsolutePath.Trim('/'), uri.UserInfo.Split(':').First(), uri.UserInfo.Split(':').Last());

Bind<IDatabase>().To<Database>().InSingletonScope().WithConstructorArgument("factory", factory);

but ConfigurationManager.AppSettings["SQLSERVER_URI"] is null.

도움이 되었습니까?

해결책

Are you trying to use the database while executing unit tests? That's not supported, the connectionstring is only inserted once the code is deployed.

Here are some additional resources:

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top