在IIS 7.0中发布MVC 3.0站点

时间:2012-06-13 07:32:13

标签: asp.net-mvc-3 entity-framework iis publish

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

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

在View Layer中,我使用了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用户来设置安全性。

1 个答案:

答案 0 :(得分:0)

可能存在两个问题

  1. 您忘记复制数据库文件(如果您使用的是紧凑型sql server)
  2. 您正在通过代码创建新数据库。您不应该在部署环境中创建数据库。如果您使用

    ,可能会发生这种情况

    System.Data.Entity.Database.SetInitializer(某种策略