0

I'm new to ASP.NET WEB API. I'm trying to create APIs that have connections to a database. For example like login method or add data to a database. But when I tried to search for example tutorial, I couldn't find an example which has a connection string inside it.

My questions are :

  1. How do I set my connection string to my database? (i.e. user name and password)
  2. Can I connect to a database which is not in my localhost? (i.e. another server)

If anyone could explain to me about ASP.NET WEB API that has a connection with database, I would really appreciate it.

**Im using visual studio 2012 right now. the database that I would use is MSSQL.

Thx

3

1 Answer 1

3

1. how do i set my connection string to my database? for example my username and password? : Its better put your connections string in the webconfig, so you can change it when you need How to: Read Connection Strings from the Web.config File

2. Can i connect to a database which is not in my localhost (for example in another server): Of course, but first, you need to choose what technology use to access database, you can use Entity Framework, Classic ADO.NET, NHibernate, for example with Entity Framework read: Entity Framework (EF) Documentation, also read: Using Web API 2 with Entity Framework 6

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.