How to switch Entity Framework database connected to

If you have a connection to a database through entity framework and you need to switch it to another database (with the exact same structure) you just need to set the Connection.ConnectionString (as seen below).
I had an application where we created a copy of the Master database when setting up a new client.  So using Entity Framework I switched from the master database to the client (depending on what the admin was doing).

using (MasterEntities aEntities = new MasterEntities())
{//Switch db connected to

 

aEntities.Database.Connection.ConnectionString = aEntities.Database.Connection.ConnectionString.Replace("OldDatabaseName", "NewDatabaseName");

      //Some Query

}

[tweetmeme only_single=”false”]
Advertisements

So you want to retrieve your test results?

When you create a test project in Visual Studio, you can load test your application, but you won’t be able to save/view results without a storage type set to database.  You can check your storage type by checking the properties on the Run Settings. (if you set it to none, you will be able run the test)

image

By default you do not have a database to store the results of you load test.  (Why your not asked during installation to create one is beyond me).

You need to run the SQLscript to create the LoadTest database.

Here is the path to the script C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\loadtestresultsrepository.sql

You will also need to set your connection string.  You need to go to Test –>Administer Test Controllers.  The click the ellipse (…) to set your connection string.

image

Now that you have a database and your connection string set,you can use the database storage type.

image