Ado.net Entity Framework: Dynamically modifying connection string information

Source: Internet
Author: User

VS introduces the powerful functionality of the Entity Framework, making it possible to quickly build a DB based application. For the Entity Framework This article does not do too much description, is actually Microsoft version of the O-r Mapping. This article only talks about how to dynamically modify the information of a database connection string.

VS provides a wizard to generate the Entity Framework to access the database's connection string and store the connection string in the Web.config file, which we typically generate at development time. When we release the product to the customer it is clear that the connection string's information needs to be modified, which needs to be changed dynamically through the code.

We can do this through local classes and local methods, with the following specific code:

Public partial class Developentities {partial void oncontextcreated () {SqlConnectionStringBuilder sb = new SqlConnection StringBuilder (((entityconnection) Connection). storeconnection.connectionstring); Sb. IntegratedSecurity = false; Sb. UserID = "User1"; Sb. Password = "xxxxxxx"; ((entityconnection) Connection). storeconnection.connectionstring = sb. ConnectionString; } }

Just a little code on it, very simple, hehe

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.