Вопрос

I am having an issue with my connectionString in a MVC 4 project.

The project is structured the following way:

Solution
   -MVC4-web app project
   -Custom DBContext project
   -Portable Area project (MvcContrib)

I am using an online Azure database for the storage, and all my models are in the custom db context. The project compiles find, and I have even got MvcContrib to work with MVC4 and Razor view engine.

After creating a new DB on Azure i try to run update-database on the DBContext project. I get the following error:

"... An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string. ... provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified ..."

My connectionString is in the App.Config file in the DbContext project:

<connectionStrings>
   <add name="CortexModelContext" providerName="System.Data.SqlClient" connectionString="Server=tcp:k5bqinuyr5.database.windows.net,1433;Database=databaseName;User ID=myname@k5bqinuyr5;Password=MySecretPassword;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;" />
</connectionStrings>

What am I doing wrong? I have duodecuple-checked the password, and the connection string. It is a copy-paste from the portal on windowsazure.com. What else can be wrong here? I feel like I have tried everything to fix this issue.

If there is some other information lacking from this post, please tell me and I will provide it.

Это было полезно?

Решение

When you have your context in a separate project the Update-Database command doesn't tend to work properly. Presumably you have your connection string in your MVC 4 project's web.config file as well?

If so use the following command:

Update-Database -ProjectName <DbContextProject> -StartupProjectName <MvcProject>

replacing the placeholders with the names of the relevant projects. That should do the job.

Cheers, Dean

Другие советы

The issue here was that I did not have the connection string in all my projects. When I added the connection string, that was currently only in my DbContext project's App.config, to the web.config of the startup project everything worked.

Good thing I didn't use a whole day to figure that out, or something.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top