1

So I want to connect to my Azure Sql Database using in a unity project, I used this code provided in the readme of 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);
        }
    }
}

The code works perfectly and connects to my DB just fine but for some reason the response DATA is always null although the response CONTENT returns a string with the data in the scores table just fine Any Idea what could be the problem?

PS: the url of the App service is not the real one I use just for demo purpose.

1 Answer 1

1

Well I've been struggling with this for hours , and after 6 min of posting the question I figure out the answer so here is the Answer so anyone that faces this problem can know the cause:

The Problem was that I didn't declare my Score Class as [Serializable] as soon as I declared it this way it worked perfectly.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.