HwyFwk: Dynamic Database Connection String

In Highway.Data you must specify the connection string to be able to access the database.  Use the following approach to allow you to specify the connection string in the web.config and utilize Web Config Transformations to target the correct database for each environment.

Modify the Install method in /Installer/HighwayDataInstaller.cs

   1:  public void Install(IWindsorContainer container, IConfigurationStore store)
   2:  {
   3:      container.Register(
   4:          Component.For<IDataContext>().ImplementedBy<HighwayDataContext>()
   5:              .DependsOn(new
   6:              {
   7:                  connectionString = @"Data Source=.;Initial Catalog=ChangeMyConnectionString;Integrated Security=SSPI;"
   8:              })
   9:              .LifestylePerWebRequest(),
  10:          ...
  11:          );
  12:  }

To

   1:  public void Install(IWindsorContainer container, IConfigurationStore store)
   2:  {
   3:      container.Register(
   4:          Component.For<IDataContext>().ImplementedBy<HighwayDataContext>()
   5:              .DependsOn(new
   6:              {
   7:                  connectionString = ConfigurationManager.ConnectionStrings["KEY"].ConnectionString
   8:              })
   9:              ...
  10:          );
  11:  }

By using the ConfigurationManager you can specify which connection string from the web.config to use.  Now just set up the Web Config transformations for each environment you deploy to and your are good to go.

HwyFwk: Disable Database Initializer for Database First Approach

Highway.Data configures a Database Initializer out of the box.  Unfortunately where I work does not allow developers to create databases on our development data server.  We usually start our development with an already formed database.

To disable migrations do the following files:

  1. Delete /App_Start/DatabaseInitializerWireup.cs
  2. Delete /Config/HighwayDatabaseInitializer.cs
  3. Edit /Installers/HighwayDataInstaller.cs and remove the registration for IDatabaseInitializer

There you go, Highway.Data will not try to drop and re-create your database now.

0 to 60 with Highway.Data Video Available!

My buddy, Shawn, over at UserGroup.tv as hanging out at the Northwest Arkansas TechFest this year and he videoed on my my talks.  The one on Highway.Data.  Highway.Data is an abstraction layer of Entity Framework (and soon Nhibernate) that  makes working with data access much easier.  It’s built in repository, unit of work and query specification really bring EF, or any ORM for that matter, to a well rounded tool for you tool belt.

This is the second video for me on UserGroup.tv and thanks to Shawn for hosting them. You can check out the videos of other presentations by me and others by going to UserGroup.tv.

Thanks, Shawn!

Calendar

<<  August 2014  >>
MonTueWedThuFriSatSun
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567

View posts in large calendar

Month List

AuthorList