简体   繁体   English

Code First Entity Framework - 更改连接字符串

[英]Code First Entity Framework - change connection string

How do I change the connection string in a code first entity framework/MVC application?如何更改代码优先实体框架/MVC 应用程序中的连接字符串? I'm trying to transfer it to a live site, but it overlooks web config values and still references my local version of the database.我正在尝试将其传输到实时站点,但它忽略了 web 配置值,并且仍然引用了我的本地数据库版本。

Here is the connection string section of my web.config:这是我的 web.config 的连接字符串部分:

<add name="MembershipConnectionString" connectionString="Data Source=192.168.1.43;Initial Catalog=Website.Models.IntranetApplication;User Id=[UserName];Password=[Password];timeout=30" />
<add name="WebsiteConnectionString" connectionString="Data Source=192.168.1.43;Initial Catalog=Website.Models.IntranetApplication;User Id=[UserName];Password=[Password];timeout=30" />
<add name="Entities" connectionString="metadata=res://*/Models.IntranetModel.csdl|res://*/Models.IntranetModel.ssdl|res://*/Models.IntranetModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=192.168.1.43;Initial Catalog=Website.Models.IntranetApplication;User Id=[UserName];Password=[Password];MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />

I'm not sure if the Entities string has any relevance, as I used Code First entity framework, and I think that only appeared when I tried to create an edmx file (although I ended up just deleting it).我不确定 Entities 字符串是否有任何相关性,因为我使用了 Code First 实体框架,并且我认为这仅在我尝试创建 edmx 文件时出现(尽管我最终只是删除了它)。 The Entities connection string has sat commented out so I don't think it's used.实体连接字符串已被注释掉,所以我认为它没有被使用。

I want entity framework to read the "WebsiteConnectionString", but it seems to want to use the local connection string, but I can't even see where that is set.我希望实体框架读取“WebsiteConnectionString”,但它似乎想使用本地连接字符串,但我什至看不到它的设置位置。 How do I change it?我该如何改变它?

The connection string or its name can be passed to constructor of DbContext .连接字符串或其名称可以传递给DbContext的构造函数。 If you are using default constructor it searches for the connection string with the same name as the name of your derived context class and if it doesn't find it, it uses this one:如果您使用的是默认构造函数,它会搜索与派生上下文 class 名称相同的连接字符串,如果找不到,它会使用这个:

Data Source=.\SQLEXPRESS; Integrated Security=True; MultipleActiveResultSets=True

With database name same like your context class.数据库名称与您的上下文 class 相同。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 更改实体框架中的连接字符串(模型优先) - Change connection string in Entity Framework(Model First) 实体框架模型的第一个连接字符串在将代码移至服务器时如何更改 - Entity framework model first connection string how to change while moving code to server 将 Entity Framework Code First 与动态连接字符串一起使用 - Using Entity Framework Code First with a dynamic connection string 实体框架代码的SQL Server Compact 4.0连接字符串首先? - SQL Server Compact 4.0 connection string for Entity Framework code first? 实体框架代码优先方法的动态连接字符串 - Dynamic connection string for entity framework code first approach 实体框架代码优先处理连接字符串配置 - Entity Framework code first approach connection string configuration Entity Framework Code First场景中ApplicationServices连接字符串的用途是什么? - What is the purpose of ApplicationServices connection string in Entity Framework Code First scenario? 将连接字符串作为参数传递给Code First Entity Framework中的构造函数 - Passing Connection String as a parameter in constructor in Code First Entity Framework 使用自定义连接字符串进行代码优先实体框架迁移 - Using a custom connection string for Code First Entity Framework Migration 在WPF代码第一个实体框架连接字符串中设置“初始目录” - Setting “Initial Catalog” in WPF Code First Entity Framework connection string
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM