【问题标题】:Why can't my Xamarin Forms application see my database table?为什么我的 Xamarin Forms 应用程序看不到我的数据库表?
【发布时间】:2017-02-27 20:01:04
【问题描述】:

我是移动开发的新手,我在使用 Xamarin Forms 应用程序时遇到了问题。我有一个 Azure 订阅,其中包含一个连接到我的数据库的移动应用程序设置。我已经从 Azure 中的 Mobile App Quickstart 链接下载了两个快速启动项目,并重新配置它们以在我的数据库中查找名为“users”的表并从中返回数据。

当我从使用 MacBook Pro 作为模拟器的 Visual Studio 运行应用程序时,列表返回为空白。我设置了几个断点,我可以看到它表明找不到资源。

当它查找表以返回一个集合时,它会在方法中遇到问题,如下所示:

public async Task<ObservableCollection<users>> GetUserItemsAsync(bool syncItems = false)
        {
            try
            {
#if OFFLINE_SYNC_ENABLED
                if (syncItems)
                {
                    await this.SyncAsync();
                }
#endif
                IEnumerable<users> items = await userTable.ToEnumerableAsync();

                return new ObservableCollection<users>(items);
            }
            //Hits this catch
            catch (MobileServiceInvalidOperationException msioe)
            {
                Debug.WriteLine(@"Invalid sync operation: {0}", msioe.Message, msioe.StackTrace, msioe.Request, msioe.Response);
            }
            catch (Exception e)
            {
                Debug.WriteLine(@"Sync error: {0}", e.Message);
            }
            return null;
        }

返回的错误如下:

"The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."

我在 catch 语句中添加了响应和请求,以尝试查看到底是什么问题。该请求返回以下内容:

{Method: GET, RequestUri: 'https://myurl.azurewebsites.net/tables/users', Version: 1.1, Content: <null>, Headers:
{
X-ZUMO-FEATURES: TT
X-ZUMO-INSTALLATION-ID: r8fv3f71-12e9-416f-a976-8are363cf3b7
Accept: application/json
User-Agent: ZUMO/3.1 (lang=Managed; os=iOS; os_version=10.2; arch=MacOSX; version=3.1.50105.0)
X-ZUMO-VERSION: ZUMO/3.1 (lang=Managed; os=iOS; os_version=10.2; arch=MacOSX; version=3.1.50105.0)
ZUMO-API-VERSION: 2.0.0
}}

我可以看到它认为要么桌子不在那里,要么它是空的。我创建了表格并用虚拟数据填充了它,所以我知道它就在那里。

也许我的过程是错误的,我从连接到我的 Azure 订阅的 Visual Studio 中创建了表。表需要以某种方式设置吗?我应该在 Azure 中使用 Easy Tables 吗?

我需要一些指导来理解为什么我的应用看不到我的数据库表。

【问题讨论】:

    标签: c# database azure xamarin


    【解决方案1】:

    除了拥有数据库之外:您是否使用 Easy Tables 设置了 Web API(或 Azure 移动应用)或使用 Azure Mobile Tables 设置了自定义 Web API 项目?

    这是移动客户端表工作所必需的。

    Easy Tables 入门快速教程是there

    可以在此处找到创建自定义移动应用后端的起点 (https://docs.microsoft.com/en-us/azure/app-service-mobile/app-service-mobile-dotnet-backend-如何使用-server-sdk)

    【讨论】:

    • 我在 Azure @woelliJ 中设置了移动应用程序,但是我没有使用 Easy Tables 创建表,而是使用 SQL 对象浏览器。遗憾的是,尝试安装 Microsoft.Azure.Server.Mobile.Tables 甚至 Microsoft.Azure.Mobile.Server.2.0.0 会引发 Nuget 的错误,指出目标框架不适合这些项目。我确实试图改变它,但它说它不能。我一直在兜圈子试图安装这些物品。
    • 数据库表不会通过创建它们直接公开。 Microsoft.Azure.Server.Mobile.Tables 包用于服务器项目。您需要通过某种网络服务(使用 Microsoft.Azure.Server.Mobile.Tables)或通过“Easy Tabes”公开您的数据库。
    • 嗯,是的,这就是您从 Azure @woelliJ 中的示例项目中得到的。所以那个元素已经存在。我做了更多的挖掘,发现这篇文章strathweb.com/2012/12/… 表明即使它们存在,您仍然需要使用 EasyTables 创建表。我已经设法做到了,我的应用程序不再陷入困境。我的下一个问题是,尽管这个过程我无法返回任何数据,但我使用 Postman 测试了 rest 语句,但它什么也没返回。
    • 我认为您将 Easy Tables 与使用 OData Tables Access 的 Web API 混淆了(早在 2012 年 - 那个博客条目的时间 - 简单的表还不存在)。我认为我们需要澄清一些事情: 1. 您是否在 Azure 上托管了服务器 ASP.NET 应用程序来访问数据库? 2. 您是否按照blog.xamarin.com/getting-started-azure-mobile-apps-easy-tables 中的说明配置了Easy Tables?如果以上都不是:您无法通过 Mobile App Tables API 访问数据库,您必须设置上述任一解决方案
    • 好的,我很抱歉,请多多包涵:D 试图让我明白这一点。 1:是的,我有,我下载了用于访问数据库的 ASP.NET 应用程序的快速启动项目,并将该项目上传到移动应用程序目录 site/wwwroot/ 2:不完全像那篇文章描述的那样,我会尝试这种方法.感谢到目前为止@woelliJ 的所有帮助,这是一个巨大的帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 2021-12-28
    相关资源
    最近更新 更多