我正在使用 ASP.NET MVC 4 - c# 连接到实时数据库,并列出结果,但是当我查看页面时,它返回以下错误:

CREATE TABLE permission denied in database 'DatabaseName'.

Description: An unhandled exception occurred during the execution
of the current web request. Please review the stack trace for more
information about the error and where it
originated in the code.



Exception Details: System.Data.SqlClient.SqlException: CREATE TABLE
permission denied in database 'DatabaseName'.

Source Error:


Line 16:         public ActionResult Index()
Line 17:         {
Line 18:             return View(db.AccControls.ToList());
Line 19:         }
Line 20

Controller :
namespace TestDBCon.Controllers
{
    public class HomeController : Controller
    {
        private DataDbContext db = new DataDbContext();

        public ActionResult Index()
        {
            return View(db.AccControls.ToList());
        }

    }
}

AccControl.cs(模型)
namespace TestDBCon.Models
{
    public class AccControl
    {
        public int ID { get; set; }
        public int ControlCode { get; set; }
        public string Nominal { get; set; }
        public string CostCentre { get; set; }
        public string Department { get; set; }
    }

    public class DataDbContext : DbContext
    {
        public DbSet<AccControl> AccControls { get; set; }
    }
}

网络配置:
<add name="DataDbContext" connectionString="Data Source=***;initial catalog=***;integrated security=True;" providerName="System.Data.SqlClient" />

我不是要创建一个表?我只是想列出结果,所以我非常困惑。它一定与MVC有关吗?

任何帮助将不胜感激!

谢谢

最佳答案

您的 web config 是否指向正确的数据库?

凭据是否正确?

如果您打算使用 MVC4 WebSecutiy() 来处理用户的身份验证和授权, Entity Framework 将在数据库中创建表。这可能会引发异常。

在这种情况下,您无法创建成员资格提供者所需的表,您需要将其从系统中排除。请参阅此 here 。或者创建一个新的 MVC4 项目并选择空模板并放入您需要的位。

关于c# - 在 "CREATE TABLE permission denied in database"ASP.NET - MVC4 中列出表结果,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14727397/

10-13 21:59