簡體   English   中英

從本地數據庫到SQL數據庫Azure的MVC實體框架

[英]MVC Entity framework from local database to SQL database Azure

可能是一個非常簡單的問題,但已經花了我幾天的時間。 問題:

在我的項目MVC實體框架中,在我的本地計算機上,它與本地數據庫連接並且可以正常工作。 我可以將項目添加到數據庫中並刪除其等。在azure中,我有一個SQL數據庫,當我將項目部署到azure時,收到以下錯誤消息

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. Verify that SQL 
Server Express is properly installed and that the Local Database Runtime 
feature is enabled.)]

我發現我的連接字符串不正確,我的應用程序無法連接到Azure SQL數據庫。 我試圖添加和更改連接字符串,但是以某種方式我無法使其正常工作。 這就是我所擁有的(減去密碼和用戶名):

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <connectionStrings><add name="InventoryEntities" connectionString="metadata=res://*/Administration.csdl|res://*/Administration.ssdl|res://*/Administration.msl;provider=System.Data.SqlClient;provider connection string=&quot;Server=tcp:****.database.windows.net,1433;Initial Catalog=****;Persist Security Info=False;User ID=****;Password=****;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;&quot;" providerName="System.Data.EntityClient" /></connectionStrings>
</configuration>

我究竟做錯了什么?

經過一夜的睡眠,我終於開始工作了。首先,我必須弄清楚要在哪個數據庫中初始化DbContext的地方。

public class EFDbContext : DbContext
{

    public EFDbContext() : base("name=InventoryEntities")
    {

    }
}

使用InventoryEntities作為WebUI的web.config中的連接字符串的名稱,我沒有更改。

就這么簡單,但是花了好幾天……

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM