locked
[Node.js] need help with azure mobile apps and sql RRS feed

  • Question

  • I created a mobile app in azure. Using the node.js backend it set everything up nicely. But it does not seem to connect to the sql database that I created in the mobile app, rather it connects to a SQLite database. How is this supposed to work?

    Saturday, July 16, 2016 10:51 PM

Answers

  • Hi AirEdwin2,

    Unfortunately, you cannot customise the name of the app setting - it must be MS_TableConnectionString.

    • Marked as answer by AirEdwin2 Monday, July 18, 2016 9:18 PM
    Monday, July 18, 2016 8:22 PM

All replies

  • Hi,

    Thank you for posting in MSDN!

    The Azure Mobile Apps Node.js SDK uses the mssql Node.js package to establish and use a connection to both SQL Express and SQL Database. This package requires that you enable TCP connections on your SQL Express instance.

    Refer to the Note below and also the Mobile App backend settings.

    Note:

    If you already have a database in the same location as the new mobile app backend, you can instead choose Use an existing database and then select that database. The use of a database in a different location is not recommended because of additional bandwidth costs and higher latencies.

    1. In the new Mobile App backend, click Settings > Mobile App > Data > +Add.

    2. In the Add data connection blade, click SQL Database - Configure required settings > Create a new database. Enter the name of the new database in the Name field.

    3. Click Server. In the New server blade, enter a unique server name in the Server name field, and provide a suitable Server admin login and Password. Ensure Allow azure services to access server is checked. Click on OK.

      Create an Azure SQL Database

    4. On the New database blade, click on OK.

    5. Back on the Add data connection blade, select Connection string, enter the login and password that you just provided when creating the database. If you use an existing database, provide the login credentials for that database. Once entered, click OK.

    6. Back on the Add data connection blade again, click on OK to create the database.

    Creation of the database can take a few minutes. Use the Notifications area to monitor the progress of the deployment. Do not progress until the database has been deployed sucessfully. Once successfully deployed, a Connection String will be created for the SQL Database instance in your Mobile backend App Settings. You can see this app setting in the Settings > Application settings > Connection strings.

    Reference: https://azure.microsoft.com/en-in/documentation/articles/app-service-mobile-node-backend-how-to-use-server-sdk/

    Hope that helps!

    Best Regards

    Sadiqh Ahmed
    ________________________________________________________________________________________________________________

    If this post was helpful to you, please upvote it and/or mark it as an answer so others can more easily find it in the future.

    Sunday, July 17, 2016 6:24 PM
  • no, this is not the answer, I am using the "quick start" and xamarin.forms

    in fact, when you create the sql databasee and then run the node.js backend API auto generator through the quick start, it doesn't even add a text column to the ToDoItem table

    the node.js backend does not connect to the SQL database, it uses SQLite and the mobile app does not work until SQLite is installed (user receives http 500 error when navigating to website at <appservicename>.azurewebsites.net), I had to npm install SQLite3 to get the site running again



    • Edited by AirEdwin2 Monday, July 18, 2016 5:38 PM
    Monday, July 18, 2016 5:36 PM
  • Hi AirEdwin2,

    If you configure a data connection in the portal, it will not use SQLite.

    A bit more detail: creating a data connection essentially creates an app setting called MS_TableConnectionString - you can see this in the Application Settings section of your app in the portal. This setting contains the connection string used to connect to SQL server, and the Node Mobile Apps SDK looks for this setting and connects to SQL Server if it is present. Check to make sure this application setting has been properly created.

    Cheers,

    Dale

    Monday, July 18, 2016 8:02 PM
  • Check if MS_SqlliteFilename appsetting is set. If set, runtime would use SQLite instead of Sql server.

    Monday, July 18, 2016 8:04 PM
  • This is not quite true - if MS_TableConnectionString exists, it will connect to SQL Server even if MS_SqliteFilename has been set as well. i.e. it will default to using SQL Server.
    Monday, July 18, 2016 8:05 PM
  • thanks for the suggestions, I will try it out, but has anyone reproduced my issue?

    steps (from the http://developer.xamarin.com/samples/xamarin-forms/WebServices/TodoAzure/ example)

    1. create new mobile app backend (mine was created in south central US)

    2. completed quick start for xamarin.forms projects, created database (I used a different connection name, myapp_TableConectionString for example instead of the default MS_TableConnectionString), loaded node.js back end

    3. this is when the site gives a 500 server error, forcing me to install sqlite3 package for node.js

    on another note, how do I develop the node.js backend? with the c# backend it allows me to download the visual studio project. for node.js do I just manage it entirely within the azure portal? I'm struggling to understand the concept

    1. the back end service is located at <site>/table/ToDoItem for example, but at the root of the website is the default "Mobile App Created" page, how do I customize this?


    • Edited by AirEdwin2 Monday, July 18, 2016 8:21 PM
    Monday, July 18, 2016 8:19 PM
  • Hi AirEdwin2,

    Unfortunately, you cannot customise the name of the app setting - it must be MS_TableConnectionString.

    • Marked as answer by AirEdwin2 Monday, July 18, 2016 9:18 PM
    Monday, July 18, 2016 8:22 PM
  • Also, you can work with the Node.js backend either locally (using an npm package) or hosted on Azure. You can find information for working with the Node.js backend at https://azure.microsoft.com/en-us/documentation/articles/app-service-mobile-node-backend-how-to-use-server-sdk/
    Monday, July 18, 2016 8:23 PM
  • this is probably the issue, thanks, I will mark it as the answer
    Monday, July 18, 2016 9:18 PM