ASP.Net SQL的ConnectionStrings配置 [英] ASP.Net SQL ConnectionStrings config

查看:603
本文介绍了ASP.Net SQL的ConnectionStrings配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图拿起ASP.Net - 并按照MVC教程:的 http://www.asp.net/mvc/tutorials/mvc-music-store-part-4 (注:我完全新的.NET框架,C#和ASP.Net )

I am trying to pick up ASP.Net - and following the mvc tutorial: http://www.asp.net/mvc/tutorials/mvc-music-store-part-4 (Note: I am totally new to the .Net framework, both C# and ASP.Net)

在开始使用教程建议使用的SQL Server Compact 4.0 - 但是,我得到了,而不是安装SQL Server的防爆preSS(因为我将在以后使用它,不只是为教程)

At the beginning the tutorial suggested to use SQL Server Compact 4.0 - But, I got the SQL Server Express installed instead (since I will be using it after, not just for the tutorial)

SELECT @@VERSION AS [Version]

的Microsoft SQL Server 2008 R2(RTM) - 10.50.1600.1(英特尔X86)2010年4月2日15:53​​:02版权所有(c)Microsoft公司前preSS与Windows高级版服务NT 6.1<&X64 GT; (编译7600:)(WOW64)

现在,我有麻烦,当我到了点设立教程的数据库连接。本教程的步骤把它添加到Web.config:

Now, I am having trouble when I got to the point to set up the db connection for the tutorial. The tutorial step to add this to the Web.config:

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

但是,这并不工作 - pretty肯定是因为我使用了不同的SQL Server。如何使这项工作有何建议?

But that doesn't work - and pretty sure it's because the different SQL Server that I am using. Suggestion on how to make this work?

我试着改变的providerName为System.Data.SqlClient的,它仍然不工作,我已经尝试了以下也:

I've tried changing the providerName to "System.Data.SqlClient" and it still doesnt work, and I've tried the following too:

  <connectionStrings>
    <add
       name="MusicStoreEntities"
       connectionString="Data Source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|MvcMusicStore.sdf"
       providerName="System.Data.SqlClient" />
  </connectionStrings>

和它下面的异常仍然不工作:提供程序未返回一个字符串ProviderManifestToken

And it still doesnt work with the following exception: The provider did not return a ProviderManifestToken string

帮助设置此ASP.Net - SQL Server的防爆preSS 2008年将是极大的AP preciated

Help with setting up this ASP.Net - SQL Server Express 2008 would be greatly appreciated!

修改

好像现在我懂了工作,至少要连接到数据库:

Seems like now I got it working, at least to connect to the db:


    
  

现在,显然数据库是空的 - 教程剪掉甚至可以说比约下载一些资源文件为DBSampeData.cs实例数据库,其他的,并把它添加到Global.asax.cs中的Application_Start方法:

Now, obviously the database is empty - the tutorial didnt even say about instantiating the database, other than downloading some asset file for the db "SampeData.cs", and add it to the Global.asax.cs Application_Start method:

System.Data.Entity.Database.SetInitializer(new MvcMusicStore.Models.SampleData());

而现在,两件事情:

And now, 2 things:


  1. 在上面的Application_Start线不似乎在调试模式下时,被打(我曾尝试重建溶液)

  1. The line above in Application_Start dont seem to be hit when in debug mode (I did try rebuild solution)

现在我收到以下错误:型号的兼容性无法进行检查,因为该数据库不包含模型元数据。确保IncludeMetadataConvention已被添加到DbModelBuilder约定。

Now I am getting the following error: Model compatibility cannot be checked because the database does not contain model metadata. Ensure that IncludeMetadataConvention has been added to the DbModelBuilder conventions.

我觉得我缺少在数据库实例中的数据 - 但不知道如何/什么 - 教程犯规多说。

I think I am missing instantiating the data in the db - but not sure how / what - the tutorial doesnt say much

推荐答案

我假设你已经恢复的数据库的副本SqlEx preSS。一旦你这样做,你应该在数据库元素添加到字符串你恢复它作为数据库的名称。为的Con​​nectionStrings一个有用的资源是 http://www.connectionstrings.com

I assume that you have restored a copy of the database to SqlExpress. Once you do that, you should add a Database element to the string with the name of the database you restored it as. A helpful resource for connectionstrings is http://www.connectionstrings.com

  <connectionStrings>
    <add
       name="MusicStoreEntities"
       connectionString="Data Source=.\SQLEXPRESS;Integrated Security=SSPI;Database=MusicStoreEntities"
       providerName="System.Data.SqlClient" />
  </connectionStrings>

请注意,你所拥有的是一个.sdf文件,这是一个SQLCE数据库的链接。该| DataDirectory目录|部分被替换为您App_Data文件夹在你的应用程序的位置。

Note that what you have is a link to an .sdf file, which is a SqlCE database. The |DataDirectory| portion is replaced with the location of your App_Data folder in your application.

这篇关于ASP.Net SQL的ConnectionStrings配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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