views:

393

answers:

1

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

I use TFS Build Server to deploy to development and take the result of that build zip it and copy it to production manually.

I also use Web Deployment Projects if that helps

What I was doing before was when the ORM started it would choose a connection string based on the name of the root folder. With Entity Framework I don't know how to do this without having to set it on every page.

+5  A: 

We have something vaguely similar, I created a class to wrap the EntityContext object, which sets the connection string appropriately - you'd need something similar, based on how you set your 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
Paddy
Good idea, I extended it a little and instead didpublic Context() : base(GetDefaultConnectionString()){ }GetDefaultConnectionString() is a public static method that gets the connection string
Stephen lacy