سؤال

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