DB connection strings in MVC applications using Entity Framework

I am working on an MVC application using Entity Framework.

After creating an EDMX, I noticed the DB connection string is located in TWO places - an app.config file in my Data class library, and a web.config file in my web application.

We want to:

  1. remove these two plain text connection strings

  2. encrypt a single connection string

  3. and use our pre-existing class library to decrypt the connection string when needed

I tried removing one or the other connection string from the config files, and DB access fails. Why are TWO required? And is there any way to do what we want in an MVC - EF project, and how would I tell EF that is what we are doing?

Thanks!

Answers


You can ignore the connection string in your EF project, I think, and just set the connection programmatically from your controller.

public class SomeController : Controller
{
    public SomeController()
    {
        /* Substitute whatever method you want to fetch your data source string here */
        /* example assumes plain text from web.config */
        string dataSource = ConfigurationManager
            .ConnectionStrings["ApplicationServices"]
            .ConnectionString;
        this.Entities = new SomeEntities(dataSource);
    }

    private SomeEntities Entities { get; set; }
}

Need Your Help

spring framework download

java eclipse spring installation unzip

So i downloaded Spring Jars from this link and I am trying to unzip the file, it keeps on complaining that some of the total path and file must not exceed 260 chars and it breaks from unzipping. H...

Displaying a message in between a asp.net repeater

asp.net .net vb.net visual-studio-2010 asprepeater

I have a dataset which returns a set of data related to some reviews. Some of the data in the dataset were migrated from the another database in to the database I am using. So the dataset contains ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.