0

我用 MVC 3.0 编写网站,它使用 EntityFrame 工作 4.0,在控制器层我有这个:

  public ViewResult Index()
    {
     return View(_DatabaseSMSEntities.People.ToList());
    }

在视图层中,我使用了 Telerik Grid:

<% Html.Telerik().Grid<ProjectWebsite.Models.People>(Model)
                    .Name("People")
                    .Columns(columns =>
                    {
                        columns.Bound(o => o.PersonID).Format(
                         "<a href='../WebPage/PersonSMSPage.aspx?personID=" + "{0}" + @"' <br/>runat=""server"">" +
                         "<img src='../../Content/themes/base/images/RegisterSMS.png' <br/>alt='{0}' />"<br/>
                        );                                           

                    })
                    .RowAction(row =>
                    {
                        if (row.Index == 0)
                        { row.DetailRow.Expanded = false; }
                    })                   
                     .Render();%>

我在 IIS 7.0 中发布了它。但它不起作用。

<connectionStrings>
    <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
    <add name="DatabaseSMSEntities" connectionString="metadata=res://*/Models.ModelDatabaseSMS.csdl|res://*/Models.ModelDatabaseSMS.ssdl|res://*/Models.ModelDatabaseSMS.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\DatabaseSMS.mdf;Integrated Security=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />
    <add name="cn1" connectionString="data source=~/ErrorsLog/Errors.db" />
  </connectionStrings>

首先,我将它发布在 D:\Pardis 中,但出现错误:

   CREATE DATABASE permission denied in database 'master'.
    An attempt to attach an auto-named database for file D:\Pardis\App_Data\DatabaseSMS.mdf failed. A database with the same name
exists, or specified file cannot be opened, or it is located on UNC share.
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 DATABASE permission denied in database 'master'.
An attempt to attach an auto-named database for file D:\Pardis\App_Data\DatabaseSMS.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

Source Error: 


Line 20:         public ViewResult Index()
Line 21:         {
Line 22:             return View(_DatabaseSMSEntities.People.ToList());
Line 23:         }
Line 24: 

然后,我将其发布在 Inetup 中,但出现错误。我在用户列表中没有 ASPNET 用户来设置安全性。

4

1 回答 1

0

可能有两个问题

  1. 您忘记复制数据库文件(如果您使用的是 sql server compact)
  2. 您正在通过代码创建一个新数据库。您不应该在部署环境中创建数据库。如果您正在使用,这可能会发生

    System.Data.Entity.Database.SetInitializer(一些策略

于 2012-10-23T02:50:24.883 回答