1

I've created an ASP.NET MVC / WebAPI 2 web application on my local environment. I am using LocalDb for my development purposes and I follow the EF "Code First" approach (I've written all my model classes and run migrations when needed). On my local environment, everything works fine.

I thought it would be a good idea to publish the app on Azure to test it out. I have created Web App + SQL instances and I am able to connect to them. I have managed to publish the website part, but unfortunately, I am not able to publish the database.

E.g. when I visit .azurewebsites.net, the page loads - but as soon as I try to log in, I get an error saying:

Cannot find the object “dbo.Locations” because it does not exist or you do not have permissions

This tells me that my tables have not successfully migrated over (even though I checkmarked "execute code-first migrations" in the "publish" wizard).

I have been trying to find a solution for 2 days now, to no avail. I have seen many that say that I need to migrate to SQL Server locally, then only will it work on Azure - however, I cannot find a way to export my data from LocalDb to SQL Server (I could not find that option even in SSMS).

Also, I found a guide - http://www.asp.net/mvc/overview/getting-started/database-first-development/creating-the-web-application - but when it comes to database publishing, it says to simply right click on the database solution and select "Publish" - I do not have a Database project/solution - for me, it's just one mdf file.

I am very new to ASP.NET so I would appreciate any help. Thank you!

  • what connection string are you using in Azure? – CtrlDot Jun 14 '16 at 03:11
  • Where would I find this? In my web.config, it is still pointing to LocalDb. But during the "publish" process, it is asking me to input the ConnectionString for the Azure SQL database (which connects successfully). – Bo Milanovich Jun 14 '16 at 03:22
  • https://azure.microsoft.com/en-us/documentation/articles/web-sites-configure/#application-settings – CtrlDot Jun 14 '16 at 03:24
  • Thanks. I've pasted the connection string that Azure gave me, however I still get the same error after saving changes - `Cannot find the object "dbo.Locations". Interestingly enough, I can see that the table `dbo.Locations` exists when browsing my "SQL Server Explorer" in my local Visual Studio – Bo Milanovich Jun 14 '16 at 03:35
  • can you try connecting directly to the database using VS and the connection string given? – CtrlDot Jun 14 '16 at 04:17
  • Same thing - I am getting an error that it cannot find dbo.Locations. – Bo Milanovich Jun 14 '16 at 04:42

1 Answers1

0

I finally figured out the problem.

The connection string in the new Azure portal does not provide the necessary Database part to it. So the web app was trying to select a table from a database without a database being selected.

I added "Database=<my database>" to the connection string and now it's working perfectly fine! The database was empty originally, but I was able to migrate the data from my local SQL Server to Azure.

Interestingly enough, the legacy Azure portal does include the Database string. I will report this to Microsoft.