vendredi 28 août 2015

connection string not working in MVC3

I am trying to connect SQL server database in visual studio 2012, but this is not working. where I am doing with my connection. plz help. I searched topic but could not find the mistake. I am using windows authentication for SQL server.
this is my Web.config setting:

    <add name="DefaultConnection"
         connectionString="server=.; database=sample; integrated security=SSPI"

this is my Global.asax.cs setting:

protected void Application_Start()

        // Use LocalDB for Entity Framework by default
        Database.DefaultConnectionFactory = new SqlConnectionFactory(@"Data Source=(localdb)\v11.0; Integrated Security=True; MultipleActiveResultSets=True");


this is DefaultConnection.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;

namespace MVCDemo.Models
    public class DefaultConnection : DbContext
         public DbSet<Employee> Employees { get; set; }


 public ActionResult Details(string id)
            int li_id = Convert.ToInt32(id);
            EmployeeContext lo_employeeContext = new EmployeeContext();
            Employee lo_employee = lo_employeeContext.Employees.Single(emp => emp.EmployeeId == li_id); 

            return View(lo_employee);

this is employee model:

using System.ComponentModel.DataAnnotations.Schema;  
    namespace MVCDemo.Models
        public class Employee
            public int EmployeeId { get; set; }
            public string Name { get; set; }
            public string Gender { get; set; }
            public string City { get; set; }

Plz Help.

Aucun commentaire:

Enregistrer un commentaire