Then, from what I have read, I cretae a new model, sweepmodel.cs, and query the DB within this file. I don't know how to do this... Do I reference the name, sweepDB?
Sorry, I just realized this sounds like such a basic question, but I am just getting into ASP MVC and it seems to be a little confusing.
no we dont connect to DB in Model there should be a business layer from which we call the database or service and do other logics and create the instance of the model and populate the data into it
to access sweepDB need to add reference to System.ConfigurationManager and inside code access it
tlitterio
Member
4 Points
20 Posts
MS SQL Data Source
Jun 20, 2012 04:34 PM|LINK
I'm confused as to how to connect to and query a MS SQL DB using MVC. I configured the web.config file with the following info:
<add name="sweepDB"
connectionString="data source=sqlserver;initial catalog=sweepdb;user id=sysupdate;password=password;"
providerName="System.Data.SqlClient" />
Then, from what I have read, I cretae a new model, sweepmodel.cs, and query the DB within this file. I don't know how to do this... Do I reference the name, sweepDB?
Sorry, I just realized this sounds like such a basic question, but I am just getting into ASP MVC and it seems to be a little confusing.
Thanks!
Mudasir.Khan
All-Star
15346 Points
3142 Posts
Re: MS SQL Data Source
Jun 20, 2012 04:43 PM|LINK
no we dont connect to DB in Model there should be a business layer from which we call the database or service and do other logics and create the instance of the model and populate the data into it
to access sweepDB need to add reference to System.ConfigurationManager and inside code access it
System.ConfigurationManager.Configuration.ConnectionStrings["sweepDB"].ConnectionString
bkis1112
Participant
1061 Points
226 Posts
Re: MS SQL Data Source
Jun 20, 2012 05:01 PM|LINK
Using ADO.NET Entity Framework to connect with data, generate model
Using Linq to query database
http://www.pluralsight-training.net/microsoft/players/PSODPlayer?author=scott-allen&name=mvc3-building-data-i&mode=live&clip=0&course=aspdotnet-mvc3-intro
http://www.asp.net/mvc
Thanks for reading my post
Trần Lê Thành Trung