MVC3教程 - 连接字符串 [英] MVC3 tutorial - connection string

查看:102
本文介绍了MVC3教程 - 连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读上MVC3 的http:// www.asp.net/mvc/tutorials/mvc-music-store-part-4 。
有一个code,它去web.config中:

 <&是connectionStrings GT;
<添加名称=MusicStoreEntities
的connectionString =数据源= | DataDirectory目录| MvcMusicStore.sdf
的providerName =System.Data.SqlServerCe.4.0/>
< /&是connectionStrings GT;

难道这就是当应用程序运行创建SDF文件?因为它没有。我完全新MVC3。谢谢!


解决方案

我已阅读并完成你指的教程,是的,自卫队(SQL Server精简)文件应该被创建,当你第一次运行教程

有可能的原因是没有为您的创建它的原因的宿主,但我会解决的两个最常见的

1)平台要求。请确保您已安装的SQL Server Compact运行时和工具的SQL Server Compact 4.0 - 包括运行时和工具支持的http://www.microsoft.com/web/gallery/install.aspx?appid=SQLCE;SQLCEVSTools_4_0

2)你通过右键点击该网站项目,并选择添加App_Data文件夹添加文件夹ASP.NET' - >程序App_Data

3)您可以通过添加以下行接线在Global.asax.cs中的的Application_Start()方法数据库初始化

 保护无效的Application_Start()
{
    System.Data.Entity.Database.SetInitializer(
            新MvcMusicStore.Models.SampleData());
    // ...其他行跟进

请务必遵循谨慎步骤4中的步骤 - HTTP ://www.asp.net/mvc/tutorials/mvc-music-store-part-4

让我知道,如果这有助于

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!

解决方案

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

这篇关于MVC3教程 - 连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆