0
我已經找到了您提供的解決方案之一無法連接到SQL Server 2008在mvc4..I跟着你的答案,但即使我得到錯誤。無法連接到SQL Server 2008遠程數據庫MVC4
public class videoDBContext : DbContext
{
static videoDBContext()
{
Database.SetInitializer<videoDBContext>(null);
}
public videoDBContext()
: base("Name=videoDBContext")
{
}
public DbSet<Video> Videos { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new VideoMap());
}
}
域類
public class Video
{
public int Id { get; set; }
public string Description { get; set; }
}
映射類作爲
public class VideoMap : EntityTypeConfiguration<Video>
{
public VideoMap()
{
// Primary Key
this.HasKey(t => t.Id);
// Properties
this.Property(t => t.Description)
.IsRequired()
.HasMaxLength(50);
// Table & Column Mappings
this.ToTable("Video");
this.Property(t => t.Id).HasColumnName("Id");
this.Property(t => t.Description).HasColumnName("Description");
}
}
控制器行動
public ActionResult Index()
{
ViewBag.Message = "Welcome to ASP.NET MVC!";
using (videoDBContext context = new videoDBContext())
{
var list = **context.Videos.ToList();**
}
return View();
}
我收到錯誤線附近:
Line 20: var s = context.Videos.ToList();
web.config
文件
<add name="videoDBContext"
connectionString="metadata=res://*/Models.xx.csdl|res://*/Models.xx.ssdl|res://*/Models.xx.msl;provider=System.Data.SqlClient;provider connection string="data source=servername;initial catalog=xx.mdf;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
請提供解決方案。我哪裏錯了?對不起,如果它很愚蠢或讓你不便。
什麼是您的遠程SQL Server(機器)的名稱,以及您嘗試連接到的數據庫的名稱是什麼?另外:您試圖在該遠程服務器(Web,Standard,Enterprise等)上連接的SQL Server 2008的哪個**版本** –
數據庫名稱= Vedios – user1865384