I am trying to develop a restful C# service with a connection to Microsoft SQL database. From what I understand, I am supposed to do the connection to the SQL server inside the following code:
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
namespace Webserver.Models
{
public class WebserverContext : DbContext
{
public WebserverContext() : base("name=WebserverContext")
{
}
public System.Data.Entity.DbSet<Webserver.Models.ApiModels.SecondlyReading> SecondlyReadings { get; set; }
}
}
The issue that I am facing is that I am not sure how to do it. I have done db connection in C# ASP.NET before and the db connection is something like:
SqlConnection conn=new SqlConnection("Data source=localhost;"+"Initial Catalog=authors;user=myuser;password=mypassword")
I tried implementing it but it does not work. I have also referenced from the following link for db connection in C# Restful Service:
Would appreciate any help.
System.Data.SqlClientin ADO.NET. - BiscuitsSqlConnectionandSqlCommandin ADO.NET (or any other data access mechanism, for that matter) to build a RESTful service, if you prefer. This won't somehow make your service become less RESTful or anything. :) - Biscuits