MVC3 tutorial - connection string

人走茶凉 提交于 2019-12-25 06:27:13

问题


I'm reading a tutorial on MVC3 http://www.asp.net/mvc/tutorials/mvc-music-store-part-4. There is a code that goes to web.config :

<connectionStrings>
<add name="MusicStoreEntities"
connectionString="Data Source=|DataDirectory|MvcMusicStore.sdf"
providerName="System.Data.SqlServerCe.4.0"/>
</connectionStrings> 

Is it supposed to create an sdf file when the application is ran ? Cause it doesn't. I'm totally new to MVC3. Thanks!


回答1:


I have read and completed the tutorial you are referring to and yes, the sdf (SQL Server Compact) file is supposed to be created when your first run the tutorial.

There could be a host of reasons why it is not being created for your but I'll address the two most common ones.

1) Platform requirements. Make sure you have installed SQL Server Compact runtime and tools SQL Server Compact 4.0 - including both runtime and tools support http://www.microsoft.com/web/gallery/install.aspx?appid=SQLCE;SQLCEVSTools_4_0

2) You've added the App_Data folder by Right Clicking on the site project and selecting 'Add ASP.NET Folder' -> App_Data

3) You wired up the database initializer in the Application_Start() method in the Global.asax.cs by adding the following line

protected void Application_Start()
{
    System.Data.Entity.Database.SetInitializer(
            new MvcMusicStore.Models.SampleData());
    //... other lines follow

Make sure you follow the steps carefully in Step 4 - http://www.asp.net/mvc/tutorials/mvc-music-store-part-4

Let me know if this helps



来源:https://stackoverflow.com/questions/6852373/mvc3-tutorial-connection-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!