所以我想在统一项目中使用连接到我的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);
}
}
}
代码工作完美,并且可以很好地连接到我的数据库,但由于某种原因,尽管响应内容返回一个包含分数表中数据的字符串,但响应数据始终为空,知道可能是什么问题吗?
PS:应用程序服务的 URL 不是我仅用于演示目的的真实 URL。
最佳答案
好吧,我已经为此苦苦挣扎了几个小时,在发布问题 6 分钟后,我找到了答案,所以这里是答案,以便任何面临此问题的人都可以知道原因:
问题是,当我以这种方式声明它时,我并没有将我的分数类声明为[Serialized],它完美地工作了。
关于c# - Unity 使用 AppServices 连接到 azure Sql 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43415155/