开发者

Newbie in MVC3 connection setup

I'm a real newbie in MVC3 but excited to learn. Guide me how to change connection from App_Data (DB.mdf) to MS SQL Server 2008.

MDF connection

<add name="MvcMusicStoreEntities" connectionString="metadata=res://*/Models.MusicStore.csdl|res://*/Models.MusicStore.ssdl|res://*/Models.MusicStore.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\MvcMusicStore.mdf;Integrated Security=True;User 开发者_开发知识库Instance=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />


This is a working one from my running project:

<add name="CONNECTION_NAME" connectionString="data source=SQL_SERVER_IP\INSTANCE_NAME; User ID=SQL_USER_NAME; Password=YOUR_PASSWORDd;Initial catalog=DB_NAME" providerName="System.Data.SqlClient" />

for your posted one, it may look like this:

as I can see, you are not following the MVC3 version of music store, or that's how it look for me as I've checked the PDF file of the MVC3 vesion and found that Jon Galloway is using the connecion string just like the one I'm using.

check out the PDF from here: http://mvcmusicstore.codeplex.com/releases/view/59112#DownloadId=197609

That's it, no other parts are required.

this is also a very very nice resource for you to find the different ways that you can do to configure your app connection string.

http://www.connectionstrings.com/sql-server-2008


From SQL Server 2008 connection strings

Data Source=myServerAddress;
Initial Catalog=myDataBase;
User Id=myUsername;
Password=myPassword;

Example:

<add name="NAME" connectionString="Data Source=.\SQLExpress; User ID=username; Password=password;Initial catalog=database" providerName="System.Data.SqlClient" />

If you are going to use Entity Framework you need to change the provider to

providerName="System.Data.EntityClient"

And modify the add tag:

<add name="Entities" connectionString="metadata=res://*/;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=.\SQLExpress;Initial Catalog=Test;Persist Security Info=True;User ID=test;Password=test;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient"/>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜