我有以下问题:
当我运行我的代码时:
public ActionResult Index()
{
return View(db.Movies.ToList());
}
我收到一条错误消息:无法完成操作。提供的 SqlConnection 未指定初始目录。
你能帮我修复连接字符串吗这是我的连接字符串:
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=aspnet-MvcMovie-20121214234752;Integrated Security=SSPI" providerName="System.Data.SqlClient" />
<add name="MovieDBContext" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Movies.mdf;Integrated Security=SSPI" providerName="System.Data.SqlClient" />
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
namespace MvcMovie.Models
{
public class Movie
{
public int ID { get; set; }
public string Title { get; set; }
public DateTime ReleaseDate { get; set; }
public string Genre { get; set; }
public decimal Price { get; set; }
}
public class MovieDBContext : DbContext
{
public DbSet<Movie> Movies { get; set; }
}
}
任何帮助将不胜感激。