我无法连接到数据库。我有一个错误"底层提供商未能打开"

时间:2014-09-23 18:59:30

标签: asp.net asp.net-mvc

我无法连接到数据库。我有一个错误"底层提供商在开放时失败了#34;。我的连接字符串是

<connectionStrings>
<add name="ElementContext"
     connectionString ="server=.; database=Element; integrated security = SSPI"
     providerName="System.Data.SqlClient"/>
</connectionStrings>

控制器

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using model_class_implementation.Models;

namespace model_class_implementation.Controllers
{
    public class ElementController : Controller
    {
        public ActionResult Element_Details()
        {
            ElementContext ElementContext = new ElementContext();
            Element element = ElementContext.Elements.Single(elem => elem.element_id == 1);
            return View(element);
        }
    }
}

包含DbContext的类是

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

namespace model_class_implementation.Models
{
    public class ElementContext : DbContext
    {
        public DbSet<Element> Elements { get; set; }
    }
}

感谢任何帮助。

0 个答案:

没有答案