【问题标题】:Changing connection Strings in asp.net MVC application在 asp.net MVC 应用程序中更改连接字符串
【发布时间】:2017-04-17 02:23:42
【问题描述】:
我尝试从 github 运行一个项目:
https://github.com/MarlabsInc/SocialGoal
它说“打开 web.config 并更改连接字符串“SocialGoalEntities”以使用您的系统。”
<connectionStrings>
<add name="SocialGoalEntities" connectionString="Data Source=.\;Initial Catalog=SocialGoal;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
我应该怎么做才能修复它?谢谢!
【问题讨论】:
标签:
asp.net-mvc-5
web-config
connection-string
【解决方案1】:
意思是根据你的系统改变连接字符串。
例如,
<connectionString><add name="DefaultConnection" connectionString="data source=Your data source; initial catalog=your db name;Integrated Security=True" providerName="System.Data.SqlClient" /></connectionString>
您可以将 DefaultConnection 替换为您喜欢的任何名称,根据您的系统替换您的数据源(您的 sql server 实例名称)和您的数据库名称。有关连接字符串的更多信息,请访问connectionstrings.com
如果尚未从包管理器控制台为项目启用迁移,则使用以下命令启用迁移:
启用迁移
使用以下命令从包管理器控制台添加迁移:
添加-迁移迁移名称
然后使用以下命令从包管理器控制台更新数据库:
更新数据库
希望这会有所帮助:)
【解决方案2】:
我假设这个项目是建立在代码优先的方法之上的。您需要提供正确的连接字符串,它指的是您的本地系统数据库和 sql 服务器。然后在您需要使用 EF 迁移工具迁移模型之后,该工具将在您的数据库中创建表。