Skip to content

Latest commit

 

History

History
31 lines (18 loc) · 2.63 KB

sql-server-data-service.md

File metadata and controls

31 lines (18 loc) · 2.63 KB

SQL Server Data Service

This feature is intended to make it easy for you to connect to SQL Server from your app. It adds appropriate references and placeholders but still relies on you loading and displaying data within the app.

Configuration

After adding this feature to your app you'll need to configure the connection appropriately. This is done in two places.

  1. In App.config specify the connection string that the app should use.
  2. In the SqlServerDataService class, optionally, add a fallback connection string to use if one is not specified in the config file.

If you change the name of the connection string from MyAppConnectionString you must do so in the config file and in SqlServerDataService.GetConnectionString.

Guidance on configuring accounts or connections for your database is beyond the scope of this document. If you're unsure of how to do this, talk to the DBA responsible for the database.

Test your connection

Apps generated by Template Studio use sample data in many pages. (These include ListDetails, Content Grid, DataGrid, and Chart.) If you're using any such page, you can easily change it to use data from a Northwind database instead. Firstly, specify a connection string to an instance of the Northwind sample database, then change SampleDataService so that it uses SqlServerDataService.AllOrders() instead of its own version of AllOrders(). If connected correctly, you'll see more data shown in the page when you run the app. If there's an error making the connection, details will be written to the Debug output window.

Connect to "real" data

Once you've specified the connection details, you will need to load and display appropriate data for your app. Do this in the way you prefer or is appropriate to your needs. This service doesn't set a limit or place restrictions on how you do this. We do, however recommend using the GetConnectionString() method as it encapsulates the logic for accessing the connection string from a hard-coded value, an app level config file, or a machine level config file.

After you've successfully connected to real data, we recommend deleting SqlServerDataService.AllOrders() and the other sample data files as your app should no longer need them.

Additional resources