为 Azure 移动应用部署数据库失败
Deploy Database Fails for Azure Mobile App
我正在尝试为我正在使用 Xamarin Forms 和 Azure 服务构建的新移动应用构建 webservice/backend。我一直在关注这个 tutorial。
一切正常,直到我进入 "Deploy the project to Azure App Service" 部分,我有 2 个相关问题。我自己的 DataObjects 和作为示例给出的标准 "ToDoList" 应用程序也遇到了同样的问题。
- 当我第一次发布时,我 select "Update database" 在发布向导的 "Settings" 选项卡上,以便将我的新 DataObjects/Schema 推送到我的新数据库。然后,我点击发布,我收到一条错误消息,说
System.Data.SqlClient.SqlException (0x80131904): Cannot attach the file '{LocalFilePath}\App_Data\{databaseName}.mdf' as database '{databaseName}'.
我注意到指定的 "App_Data" 文件夹中没有任何内容,我是否需要做一些事情来构建 .mdf 之前发布到应用服务?
- 出现这个错误后,我尝试重新发布数据库,发布向导有2处不同。首先,我不再有 "Update Database" 选项,我在“设置”选项卡上只有 "Execute Code First Migrations" 选项,而且它是灰色的。其次,预览选项卡显示 "No databases are selected to publish"
我已经尝试通过三种不同的方式通过应用服务发布数据库,并且每种方式都给我提供了与上述完全相同的场景,所以我认为我只是错过了一些明显的东西,因为我是新手到 Azure 和移动应用程序开发。
- 通过 Azure 门户创建移动应用后端 + 服务 + 数据库,然后从 Azure 门户部署 "QuickStart" 项目。
- 遵循与上述类似的教程,但该教程专门用于发布默认插入的 ToDoList 数据库架构。这是我关注的tutorial
- 遵循上面的教程,但使用我自己的自定义 DataObjects 而不是教程中描述的那些。
我已经阅读了使 "Execute Code First Migrations" 可用的方法,但我还没有找到任何实际上允许我部署数据库的方法,因为它一直在说 "No databases are selected to publish",我无法在初始失败后显示 "Update Database" 选项。有什么明显的我遗漏的吗?
When I go to publish the first time, I select "Update database" on the "Settings" tab in the Publish Wizard in order to push my new DataObjects/Schema through to my new database. Then, I hit publish, and I get an error back saying System.Data.SqlClient.SqlException (0x80131904): Cannot attach the file '{LocalFilePath}\App_Data{databaseName}.mdf' as database '{databaseName}'. I notice that there is NOTHING in the specified "App_Data" folder, is it possible that I need to do something to build the .mdf prior to publishing to the app service?
正如官方 document 提到的那样 在发布 Web 向导中更新数据库 如下:
you select the check box labeled Update database in the Publish Web wizard. This check box is shown for SQL Server databases that the application accesses without using an Entity Framework Code First context class.
如果在部署应用程序之前未创建源本地数据库,则会出现如下错误:
有关详细信息,您可以参考此 document 中的 dbDacFx Web 部署提供程序 部分。
After this error occurs, and I try to re-publish the database, and the Publish Wizard has 2 differences. First, I no longer have the "Update Database" option, I only have the "Execute Code First Migrations" option on the Settings Tab, and it is grayed out. Second, the Preview tab says "No databases are selected to publish"
执行代码优先迁移(应用程序启动时 运行s) 显示为应用程序使用 Entity Framework 代码优先上下文访问的数据库class。
When you select this option, the deployment process automatically configures the application Web.config file on the destination server so that Code First uses the MigrateDatabaseToLatestVersion
initializer class.
如果您在程序包管理器控制台中 运行 Enable-Migrations 命令,则可以 select 此复选框。有关详细信息,您可以参考此 document.
中的 Entity Framework Code First Migrations 部分
对于一种简单的方法,您可以利用 Azure 门户中的 "QuickStart" 项目首先通过 EF 代码迁移您的数据库。部署项目时,在 VS 发布 Web 向导中的 "Settings > Databases" 下使用目标数据库(例如 Azure 数据库)连接字符串更新本地连接字符串,如下所示:
我正在尝试为我正在使用 Xamarin Forms 和 Azure 服务构建的新移动应用构建 webservice/backend。我一直在关注这个 tutorial。
一切正常,直到我进入 "Deploy the project to Azure App Service" 部分,我有 2 个相关问题。我自己的 DataObjects 和作为示例给出的标准 "ToDoList" 应用程序也遇到了同样的问题。
- 当我第一次发布时,我 select "Update database" 在发布向导的 "Settings" 选项卡上,以便将我的新 DataObjects/Schema 推送到我的新数据库。然后,我点击发布,我收到一条错误消息,说
System.Data.SqlClient.SqlException (0x80131904): Cannot attach the file '{LocalFilePath}\App_Data\{databaseName}.mdf' as database '{databaseName}'.
我注意到指定的 "App_Data" 文件夹中没有任何内容,我是否需要做一些事情来构建 .mdf 之前发布到应用服务? - 出现这个错误后,我尝试重新发布数据库,发布向导有2处不同。首先,我不再有 "Update Database" 选项,我在“设置”选项卡上只有 "Execute Code First Migrations" 选项,而且它是灰色的。其次,预览选项卡显示 "No databases are selected to publish"
我已经尝试通过三种不同的方式通过应用服务发布数据库,并且每种方式都给我提供了与上述完全相同的场景,所以我认为我只是错过了一些明显的东西,因为我是新手到 Azure 和移动应用程序开发。
- 通过 Azure 门户创建移动应用后端 + 服务 + 数据库,然后从 Azure 门户部署 "QuickStart" 项目。
- 遵循与上述类似的教程,但该教程专门用于发布默认插入的 ToDoList 数据库架构。这是我关注的tutorial
- 遵循上面的教程,但使用我自己的自定义 DataObjects 而不是教程中描述的那些。
我已经阅读了使 "Execute Code First Migrations" 可用的方法,但我还没有找到任何实际上允许我部署数据库的方法,因为它一直在说 "No databases are selected to publish",我无法在初始失败后显示 "Update Database" 选项。有什么明显的我遗漏的吗?
When I go to publish the first time, I select "Update database" on the "Settings" tab in the Publish Wizard in order to push my new DataObjects/Schema through to my new database. Then, I hit publish, and I get an error back saying System.Data.SqlClient.SqlException (0x80131904): Cannot attach the file '{LocalFilePath}\App_Data{databaseName}.mdf' as database '{databaseName}'. I notice that there is NOTHING in the specified "App_Data" folder, is it possible that I need to do something to build the .mdf prior to publishing to the app service?
正如官方 document 提到的那样 在发布 Web 向导中更新数据库 如下:
you select the check box labeled Update database in the Publish Web wizard. This check box is shown for SQL Server databases that the application accesses without using an Entity Framework Code First context class.
如果在部署应用程序之前未创建源本地数据库,则会出现如下错误:
有关详细信息,您可以参考此 document 中的 dbDacFx Web 部署提供程序 部分。
After this error occurs, and I try to re-publish the database, and the Publish Wizard has 2 differences. First, I no longer have the "Update Database" option, I only have the "Execute Code First Migrations" option on the Settings Tab, and it is grayed out. Second, the Preview tab says "No databases are selected to publish"
执行代码优先迁移(应用程序启动时 运行s) 显示为应用程序使用 Entity Framework 代码优先上下文访问的数据库class。
When you select this option, the deployment process automatically configures the application Web.config file on the destination server so that Code First uses the
MigrateDatabaseToLatestVersion
initializer class.
如果您在程序包管理器控制台中 运行 Enable-Migrations 命令,则可以 select 此复选框。有关详细信息,您可以参考此 document.
中的 Entity Framework Code First Migrations 部分对于一种简单的方法,您可以利用 Azure 门户中的 "QuickStart" 项目首先通过 EF 代码迁移您的数据库。部署项目时,在 VS 发布 Web 向导中的 "Settings > Databases" 下使用目标数据库(例如 Azure 数据库)连接字符串更新本地连接字符串,如下所示: