2

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.

2 Answers 2

5

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
Sign up to request clarification or add additional context in comments.

1 Comment

Good idea, I extended it a little and instead did public Context() : base(GetDefaultConnectionString()) { } GetDefaultConnectionString() is a public static method that gets the connection string
4

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.