【问题标题】:Unity Connect to azure Sql Database with AppServicesUnity 使用 AppServices 连接到 Azure Sql 数据库
【发布时间】:2017-04-15 00:13:18
【问题描述】:

所以我想在一个统一项目中连接到我的 Azure Sql 数据库, 我使用了app services Github project的自述文件中提供的这段代码:

    public class AzureConnect : MonoBehaviour {
    private MobileServiceClient _client;
    private MobileServiceTable<Score> _table;
    // Use this for initialization
    void Start () {
        _client = new MobileServiceClient("https://myService.azurewebsites.net"); // <- add your app url here.
        _table = _client.GetTable<Score>("Score");
        ReadItems();
    }
    private void ReadItems()
    {
        StartCoroutine(_table.Read<Score>(OnReadItemsCompleted));
    }

    private void OnReadItemsCompleted(IRestResponse<Score[]> response)
    {
        if (!response.IsError)
        {
            Debug.Log("OnReadCompleted: " + response.Url + " data: " + response.Content);//content shows the content of the table properly
            Score[] items = response.Data;//Data is always null
            Debug.Log("Todo items count: " + items.Length);
        }
        else
        {
            Debug.LogWarning("Read Error Status:" + response.StatusCode + " Url: " + response.Url);
        }
    }
}

代码运行良好,可以很好地连接到我的数据库,但由于某种原因,响应 DATA 始终为空,尽管响应 CONTENT 返回一个字符串,其中包含分数表中的数据就好了任何想法可能是什么问题?

PS:App 服务的 url 不是真实的,我只是用于演示目的。

【问题讨论】:

    标签: c# azure unity3d unity5


    【解决方案1】:

    好吧,我已经为此苦苦挣扎了好几个小时,在发布问题 6 分钟后,我找到了答案,所以这里是答案,所以遇到这个问题的任何人都可以知道原因:

    问题是我没有将我的 Score Class 声明为 [Serializable],只要我这样声明它就可以完美运行。

    【讨论】:

      猜你喜欢
      • 2020-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多