在Azure上使用LocalDb MDF文件

时间:2022-06-05 02:49:08

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的FTP发送出去。mdf进入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?

我的问题是,是否有一种方法可以让我的Azure网站连接到App_Data文件夹中的MDF文件,或者我*使用Azure SQL数据库?

2 个解决方案

#1


30  

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。如果您正在使用代码优先迁移,那么将LocalDB部署到Compact是很容易的;否则,在部署之前必须迁移到SQL Server Compact。如果您决定使用Compact,那么您必须确保数据库引擎得到部署,您可以在本教程中找到相关的说明:

http://www.asp.net/mvc/tutorials/deployment/deployment-to-a-hosting-provider/deployment-to-a-hosting-provider-deploying-sql-server-compact-databases-2-of-12

http://www.asp.net/mvc/tutorials/deployment/deployment-to-a-hosting-provider/deployment-to-a-hosting-provider-deploying-sql-server-compact-databases-2-of-12

#2


2  

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部署,以简化发布体验。

http://msdn.microsoft.com/en-us/library/dd465318(v=vs.100).aspx

http://msdn.microsoft.com/en-us/library/dd465318(v = vs.100). aspx

http://www.hanselman.com/blog/TinyHappyFeatures3PublishingImprovementsChainedConfigTransformsAndDeployingASPNETAppsFromTheCommandLine.aspx

http://www.hanselman.com/blog/TinyHappyFeatures3PublishingImprovementsChainedConfigTransformsAndDeployingASPNETAppsFromTheCommandLine.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,您可以通过门户导入/导出数据。

#1


30  

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。如果您正在使用代码优先迁移,那么将LocalDB部署到Compact是很容易的;否则,在部署之前必须迁移到SQL Server Compact。如果您决定使用Compact,那么您必须确保数据库引擎得到部署,您可以在本教程中找到相关的说明:

http://www.asp.net/mvc/tutorials/deployment/deployment-to-a-hosting-provider/deployment-to-a-hosting-provider-deploying-sql-server-compact-databases-2-of-12

http://www.asp.net/mvc/tutorials/deployment/deployment-to-a-hosting-provider/deployment-to-a-hosting-provider-deploying-sql-server-compact-databases-2-of-12

#2


2  

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部署,以简化发布体验。

http://msdn.microsoft.com/en-us/library/dd465318(v=vs.100).aspx

http://msdn.microsoft.com/en-us/library/dd465318(v = vs.100). aspx

http://www.hanselman.com/blog/TinyHappyFeatures3PublishingImprovementsChainedConfigTransformsAndDeployingASPNETAppsFromTheCommandLine.aspx

http://www.hanselman.com/blog/TinyHappyFeatures3PublishingImprovementsChainedConfigTransformsAndDeployingASPNETAppsFromTheCommandLine.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,您可以通过门户导入/导出数据。