3

I'm creating an API meant to consume data on an exiting SQL Azure database. I'm creating this API based on ASP.NET's Web API 2.

I'm a complete newbie on this area. This is why I've been following ASP.NET tutorials. I'm able to create a Web API and create models/controllers. But on the database side, every tutorial I come across is about creating a database from the scratch dedicated for the API, not about connecting an existing database that is consumed by the API.

How can I make the connection and query the database from the API?

Tutorials I've followed

1
  • Check for database connectionString and try reading about how to use that connectionString to consume database.. Commented Jun 6, 2016 at 3:41

1 Answer 1

4
  1. Login to the Windows Azure management portal
  2. Click on "SQL DATABASES" in the menu
  3. Click on the database you want to connect to
  4. Right at the bottom click on "View SQL Database connection strings for ADO .Net, ODBC, PHP, and JDBC"
  5. Copy the connection from the "ADO.NET" text box and change the password to the valid password.
  6. Now in your WEB API project open the .config file and paste the connection string in the designated element:

Connection string:

  <connectionStrings>
    <add name="MyAzzureConnection" connectionString="paste the connection string from Azure here" />
  </connectionStrings>

Now you can write your data access code using the technology of your choice, just make sure you use the Azure connection from the Web.config file.

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

1 Comment

Could you please fix the broken link?

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.