【问题标题】:Azure Website doesn't recognize my Database's Table after changing the Schema更改架构后 Azure 网站无法识别我的数据库表
【发布时间】:2023-03-28 07:33:01
【问题描述】:

我有一个运行和使用 Azure SQL 数据库的 Microsoft Azure 网站,其唯一目的是存储和检索用户帐户。但是,我还需要一个移动客户端,因此根据大量在线教程(例如THIS),我必须将数据库表的“模式”从“dbo”更改为我的移动服务名称“usermobileservice”。

这是使用 SQL 查询完成的:

CREATE SCHEMA usermobileservice;
ALTER SCHEMA usermobileserviceTRANSFER dbo.usertable;

这成功了,我可以使用我的移动应用程序连接到数据库,但现在我无法使用我的 Azure 网站访问数据库!给我这个错误:

Server Error in '/' Application.

Invalid object name 'UserTable'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Data.SqlClient.SqlException: Invalid object name 'UserTable'.

我相信 ASP.NET Web 应用程序无法再找到数据库表,因为我更改了架构?在网站和移动服务之间共享数据的正确方法是什么?

【问题讨论】:

  • 那是因为您更改了架构。您需要更新 Web 应用程序查询以使用 usermobileservice.UserTable,或创建一个将 usermobileservice 作为默认架构的 SQL 帐户,并更新连接字符串以使用此用户。
  • 天哪!这解释了很多。由于制作全新的 SQL 很麻烦,先生,我该如何更新 Web 应用程序查询? @BrendanGreen

标签: asp.net azure azure-sql-database azure-mobile-services azure-web-roles


【解决方案1】:

对于那些有同样问题的人,只需将调用表(架构已更改)的 SQL 查询替换为:

your_mobile_service_name.Your_Table_Name

就我而言:

usermobileservice.UserTable

例子:

SELECT * FROM usermobileservice.UserTable

感谢@Brendan Green 的指导!

【讨论】:

    猜你喜欢
    • 2021-03-14
    • 1970-01-01
    • 1970-01-01
    • 2017-10-22
    • 1970-01-01
    • 1970-01-01
    • 2012-01-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多