asp.net-mvc 在 Azure 上使用 LocalDb MDF 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12870996/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using a LocalDb MDF file on Azure
提问by Mark Heath
I am developing an ASP.NET MVC website, which I want to host on Azure Websites. While in development, I have been using an MDF file in my App_Data directory with a connection string looking like this:
我正在开发一个 ASP.NET MVC 网站,我想将其托管在 Azure 网站上。在开发过程中,我一直在 App_Data 目录中使用一个 MDF 文件,其中的连接字符串如下所示:
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=MyApp;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\MyApp.mdf;MultipleActiveResultSets=true" providerName="System.Data.SqlClient" />
To try it out on Azure, I was hoping I could leave this connection string as is, and simply FTP my MyApp.mdf into the App_Data folder on Azure, since it is all set up with the example data I want to use. However, when I tried to access my site, I ran into the following error:
为了在 Azure 上试用它,我希望我可以保留这个连接字符串,只需将我的 MyApp.mdf FTP 到 Azure 上的 App_Data 文件夹中,因为它全部设置了我想要使用的示例数据。但是,当我尝试访问我的网站时,遇到了以下错误:
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 LocalDB installation. Verify that SQL Server Express is properly installed and that the LocalDB feature is enabled.)
与 SQL Server 建立连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接。(提供者:SQL 网络接口,错误:52 - 无法找到 LocalDB 安装。验证 SQL Server Express 是否已正确安装并且 LocalDB 功能已启用。)
My question is, is there a way I can run my Azure website connecting to an MDF file in my App_Data folder, or am I forced to use an Azure SQL database?
我的问题是,有没有办法运行连接到 App_Data 文件夹中的 MDF 文件的 Azure 网站,或者我是否被迫使用 Azure SQL 数据库?
采纳答案by tdykstra
You can't use an .mdf file in App_Data, but you aren't forced to SQL Azure -- you can use SQL Server Compact. Deployment from LocalDB to Compact is easy if you are using Code First Migrations; otherwise you will have to migrate to SQL Server Compact before you deploy. If you decide to go with Compact you'll have to make sure the database engine gets deployed, and you can find instructions for that in this tutorial:
您不能在 App_Data 中使用 .mdf 文件,但您不会被迫使用 SQL Azure——您可以使用 SQL Server Compact。如果您使用 Code First Migrations,从 LocalDB 到 Compact 的部署很容易;否则,您必须在部署之前迁移到 SQL Server Compact。如果您决定使用 Compact,则必须确保部署了数据库引擎,您可以在本教程中找到相关说明:
回答by Bryan Wood
You'll have to use SQL Azure to use the Websites/Cloud Service features.
您必须使用 SQL Azure 才能使用网站/云服务功能。
If you haven't already you'll probably want to have a look at web.config transformations with web deploy to ease the publishing experience.
如果你还没有,你可能想看看 web.config 转换和 web 部署,以简化发布体验。
http://msdn.microsoft.com/en-us/library/dd465318(v=vs.100).aspx
http://msdn.microsoft.com/en-us/library/dd465318(v=vs.100).aspx
You can import your data into the SQL Azure DB via the management tools or if you're using SQL Server 2012 you can import/export data via the portal.
您可以通过管理工具将数据导入 SQL Azure DB,或者如果您使用的是 SQL Server 2012,则可以通过门户导入/导出数据。

![asp.net-mvc /obj/debug 破坏构建中的 TemporaryGeneratedFile_[guid]](/res/img/loading.gif)