Various context-based connection strings with Entity Framework

I have a web forms application that uses entity framework, the application is deployed to the development box, my local machine and the production box. Each of them has different connection strings. What is the best way to handle this.

I am using TFS Build Server to deploy for development and get the result of this build, zip and copy it to production manually.

I also use web deployment projects if that helps

What I did before was when the ORM started it, it will select the connection string based on the root folder name. With Entity Framework, I don't know how to do this without setting it on every page.

+2


source to share


2 answers


We have something vaguely similar, I created a class to wrap an EntityContext object that sets the connection string correctly - you need something similar based on how you set up the connection string:



Public Class MyEntityModel

    Private _dataContext As Entities

    Public Sub New()

        Dim entityBuilder As New EntityConnectionStringBuilder()

        entityBuilder.ProviderConnectionString = MyApplicationConnectionString

        entityBuilder.Metadata = "res://*/"

        entityBuilder.Provider = "System.Data.SqlClient"

        _dataContext = New Entities(entityBuilder.ConnectionString)

    End Sub

    Public Function DataContext() As Entities
        Return _dataContext
    End Function

End Class

      

+5


source


FYI You can now use config transformations in VS 2010: http://msdn.microsoft.com/en-us/vstudio/Video/ff801895



+4


source







All Articles