I am deploying a site to Azure that uses EF6 using the VS Studio publish option.
I am using the default behavior for for database naming rather than specifying a connection string as I do development from multiple machines which have a mixture of localDB or SQL Express:
public WebsiteDBContext() : base("WebsiteDBContext") The EF code is all in a separate project to the website as it is used on multiple websites sharing the same DB.
When I publish to Azure the connection strings added to web.config include a namespace from the project the DBContext code is in:
<add name="Utils.Models.WebsiteDBContext" connectionString="Data Source=****.database.windows.net;Initial Catalog=MyDatabase;Persist Security Info=True;User ID=****;Password=****" providerName="System.Data.SqlClient" /> <add name="DefaultConnection" connectionString="Data Source=tcp:****.database.windows.net,1433;Initial Catalog=CreweAllen;User ID=****;Password=****" providerName="System.Data.SqlClient" /> <add name="Utils.Models.WebsiteDBContext_DatabasePublish" connectionString="Data Source=****.database.windows.net;Initial Catalog=MyDatabase;Persist Security Info=True;User ID=****;Password=****" providerName="System.Data.SqlClient" /> The Migration fails to run I think because it can't find the database.
If I manually create the tables and remove the migration table creations the website fails with: 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: 52 - Unable to locate a Local Database Runtime installation.
But if edit the web.config and remove "Utils.Models." from the WebsiteDBContext connection string but not the WebsiteDBContext_DatabasePublish it connects to the database ok.
How can I get the connections correctly named and the migration to run? Have tried hard but failed to find a solution.
Thanks