简体   繁体   中英

Data-first Azure deployment using Entity Framework database issues

I am in the process of deploying my web-app to Azure using data-first Entity framework. I have published my site, but when the page loads, my UI framework appears with the text:

在此处输入图片说明

Which leads me to believe that my database was not deployed correctly. Here's the process I took:

  1. Created App Service.
  2. Explore additional Azure Services
  3. Add SQL Database -> Admin username: adminuser1, admin pass: adminpass1, Connection String Name: UnearthEntities (username and pass are temp for stackoverflow post)
  4. Create and Publish

This gets me to that screenshot above.

  1. When I go to the publish page, under the summary tab I click settings and under that settings tab there I see my three databases:

    ApplicationDbContext (DefaultConnection), SongModelDbContext, and UnearthEntities.

  2. All of their remote connection string inputs were blank so I went to my web.config and found my connectionStrings, I removed my ip and username and pass just incase it was necessary for stack overflow security

Here's my Unearth Entities Connection string

    <add name="UnearthEntities" connectionString="metadata=res://*/Data.UnearthEntities.csdl|res://*/Data.UnearthEntities.ssdl|res://*/Data.UnearthEntities.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=xxx.xxx.xxx.xx;initial catalog=marsman57_;integrated security=False;user id=stackoverflowid1;password=stackoverflowpasswd1;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

I added the UnearthEntities data source into each remote connection string input. I also had a DefaultConnection string, do I need to add this one somewhere?:

 <add name="DefaultConnection" connectionString="Data Source=xxx.xxx.xxx.xx;Initial Catalog=marsman57_;Integrated Security=False;User Id=stackoverflowid1;Password=stackoverflowpasswd1;" providerName="System.Data.SqlClient" />

I tried following this tutorial, but it's a bit dated. Where am I going wrong, or what next steps do I need to take? Thank you!

https://docs.microsoft.com/en-us/aspnet/mvc/overview/getting-started/database-first-development/publish-to-azure

EDIT: PROGRESS FROM INITIAL QUESTION:

Here's where I am at. I used SSMS and did Tasks->Deploy Database to Microsoft Azure SQL Database this database now shows up in my SQL Server Object Explorer in visual studio with all the tables. I went to my Azure account and copied the ADO.NET connection string and pasted it in my UnearthEntities connection string as:

<add name="UnearthEntities" connectionString="metadata=res://*/Data.UnearthEntities.csdl‌​|res://*/Data.Uneart‌​hEntities.ssdl|res:/‌​/*/Data.UnearthEntit‌​ies.msl;provider=Sys‌​tem.Data.SqlClient;p‌​rovider connection string=&quot;data source=unearthappdbserver.database.windows.net,1433;initial catalog=marsman57_;integrated security=False;user id=unearthadmin;password=serverpasswd;MultipleActiveResultSe‌​ts=True;App=EntityFr‌​amework&quot;" providerName="System.Data.EntityClient" />

Next, in my publish settings, I clicked the ellipses and selected the server I just imported: 在此处输入图片说明

Upon publishing, I still retain the same error :(

An error occurred while processing your request.

You could disable the customErrors for retrieving more detailed error information to narrow this issue. And you could leverage kudu and navigate to D:\\home\\site\\wwwroot and change your web.config file or redeploy your web application.

The web.config would look like this:

<system.web>
   <customErrors mode="Off"/>
</system.web>

I tried following this tutorial, but it's a bit dated. Where am I going wrong, or what next steps do I need to take? Thank you!

Since you are using Database First, you need to publish your database to SQL Azure. In order to migrate your SQL Server database to Azure SQL Database, you could follow the approaches below:

  • Use SQL Server Management Studio (SSMS) , right click your database, then choose "Tasks > Export Data", configure the Data Source and Destination. More details, you could refer to here .

  • Use the SSIS Import and Export Wizard from Visual Studio, more details you could refer to here .

  • Use Data Migration Assistant, more details you could refer to here .

Note: You need to set server firewall for your azure SQL Database and add the current IP address of your computer to access your Azure SQL Database.

After you migrated your database to SQL Azure, you could just update the connection string ( UnearthEntities ) under your web.config with the settings (data source, initial catalog, user id, password) from your SQL Azure or you could update your connection string when using the publish wizard under "Publish > Settings".

I added the UnearthEntities data source into each remote connection string input. I also had a DefaultConnection string, do I need to add this one somewhere?

You need to update the connection string your are using with the related Entity Data Model.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM