Converting Entity Framework connection string to SQL Server Express
我的项目有一个Entity Framework连接字符串,但是我想连接到SQL Server Express数据库,所以我认为我必须将连接字符串更改为SQL Server Express-但是如何?
我想在连接字符串下方更改。只需更改同一SQL Server mdf文件的连接字符串,连接数据库是否还足够?
1 2 3 4 5 6 7 | <add name="MyEntities" connectionString="metadata=res://*/Model.MyEntities.csdl|res://*/Model.MyEntities.ssdl|res://*/Model.TravldbEntities.msl; provider=System.Data.SqlClient; provider connection string="Data Source=sandiego; Initial Catalog=mydatabse;Persist Security Info=True; User ID=user;Password='password';MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" /> |
您尝试了什么?我不熟悉EF,但为什么不尝试尝试类似于普通C#应用程序的连接方式:
1 2 3 4 5 | <add name="MyEntities" connectionString="provider=System.Data.SqlClient; Data Source=sandiego; -- maybe needs to be sandiego\\SQLEXPRESS? User ID=user; Password=password;"> |
仅当您确定需要时才指定MARS属性。
代替此:
1 | Data Source=sandiego |
使用此:
1 | Data Source=SomeMachineNameOrIP\\SQLExpress |
这是另一个类似的答案。