2011-03-25 43 views
0

我是一個真正的MVC3新手,但很興奮學習。指導我如何改變從App_Data文件(DB.mdf)到MS SQL Server的連接2008MVC3連接設置新手

MDF連接

<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" /> 

回答

3

這是一個正在運行的從我的正在運行的項目:

<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" /> 

爲你可能看起來像這樣:

正如我所看到的,你沒有遵循MVC3版本的音樂商店,或者這是它的樣子,因爲我已經檢查了MVC3的PDF文件vesion,發現Jon Galloway正在使用connecion字符串,就像我正在使用的字符串。

退房的PDF從這裏:http://mvcmusicstore.codeplex.com/releases/view/59112#DownloadId=197609

就是這樣,不需要其它部件。

這也是一個非常非常好的資源,可以幫助您找到配置應用程序連接字符串的不同方法。

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

1

SQL Server 2008 connection strings

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

例子:

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

如果你要使用Entity Framework您需要的供應商變更爲

providerName="System.Data.EntityClient" 

並修改add標籤:

<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"/>