2012-06-13 86 views
0

我節目的網站,MVC 3.0,它使用EntityFrame工作4.0,在控制器層我有這樣的:
發佈MVC 3.0站點在IIS 7.0

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

,並鑑於層我使用Telerik的網格:

<% 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用戶在用戶列表中設置安全性。

+0

那麼究竟是什麼不起作用可能發生麼?發佈自己或發佈的網站? – LukeP

+0

我發現我應該添加「User Instance = True;」,但它有時會工作,並且不會再工作 –

回答

0

可能有兩個問題

  1. 你忘記複製你的數據庫文件(如果使用的SQL Server Compact)
  2. 您正在創建通過代碼的新數據庫。您不應該在部署環境中創建數據庫。這可以,如果你使用的是

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