簡體   English   中英

從vs2013在Azure中創建數據庫

[英]Create DB in azure from vs2013

我按照本教程的步驟1-5進行操作,並在本地對其進行了檢查,以及它的正常工作http://www.asp.net/mvc/tutorials/mvc-5/introduction/getting-started現在,我將解決方案轉換為Azure並將其發布而且我能夠看到Asp頁面,但是當我導航到電影(在URL中)時出現錯誤,我想這與數據庫有關,在app數據文件夾中,我有本地數據庫,有一種方法將其轉換為azure數據庫或存儲 ,以便能夠從azure url而不是從本地更新數據?

最好的方法是創建一個Azure SQL數據庫 請注意,在本教程中,您可能可以在步驟4處停止,因為EF Code First將負責生成模式。

然后,您需要將Web.config轉換設置為Web.Debug.config和Web.Release.config文件,並且Visual Studio將在部署時自動更改您的連接字符串。

在您的Web.config中,找到您的連接字符串:

<connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=localhost;Initial Catalog=DatabaseName;Integrated Security=SSPI;" providerName="System.Data.SqlClient" />
</connectionStrings>

(請注意,如果使用SQL Express或其他方法,您的實際連接字符串可能會有所不同)

然后將以下內容添加到Web.Debug.config和Web.Release.config中:

<connectionStrings>
    <add name="DefaultConnection" connectionString="Server={the connection string from the Azure portal}" xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>

確保連接字符串名稱與Web.config中的名稱相同,以便它知道要替換的字符串。

現在,當您在本地運行項目時,它將連接到本地數據庫。 當您部署到Azure時,它將連接到Azure SQL數據庫。

暫無
暫無

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

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