格式如下
1
2
3
4
5
6
| < add name = "DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0; AttachDbFilename=|DataDirectory|\.mdf; Initial Catalog = aspnet -RyanWebsite-20150419075941; Integrated Security = True " providerName = "System.Data.SqlClient" /> |
當我想要把原本建立在localdb的資料庫改到遠端的SQL Server上面,就要把連線字串改為之前在ASP.NET Webform一樣的連線字串
此時ASP.NET MVC的資料庫在登入時就會直接建立到遠端資料庫
以下是連線到遠端資料庫之連線字串,格式如下
1
2
3
4
5
6
| < add name = "DefaultConnection" connectionString="Persist Security Info = False ;Data Source = 123 .123.123.123; Initial Catalog = NORTHWND ; User Id = ACCOUNT ; Password = PASSWORD " providerName = "System.Data.SqlClient" /> |
在這邊做個紀錄
2015/5/4 更新
如果是連到localdb,仍要指定DB的連線可以使用以下的字串
1
2
3
4
5
| < add name = "TESTConnection" connectionString="Server=(localdb)\\v11.0; Integrated Security = true ; Initial Catalog = TEST ;" providerName = "System.Data.SqlClient" /> |