Skip to main content

Posts

Showing posts from January, 2013

Restoring a DB when the database is “In Use”

We’ve all run into this issue before. We have a backup of a database that we need to restore into a DEV/QA environment, but when we attempt to restore, we get the “ System.Data.SqlClient.SqlError:  Exclusive access could not be obtained because the database is in use ” This error can be very frustrating to get around and a person can spend a LONG time trying to kill all of the attached queries/threads. I know I’ve (almost) lost my sanity on more than 1 occasiaion trying to do this. The good news is that I’ve found a simple/easy way to restore a backup when the database is in use Steps: Setting the database to single user (you!) restore the backup set it back to multiuser Here is the SQL Script I use. Simple and fast. Enjoy!

Repository Pattern with Cross Table Objects

  In a recent post, I mentioned one of the advantages of using Entity Framework in your application is that you can build a generic repository class very easily. Of course, its not realistic to think that all access to the data will be a single table at a time. Most often it’s the case where you need to return data that spans multiple tables. I’m  going to show you how I created a simple repository class that spans tables. Creating the Summary/DTO Object The first thing I like to start with is to create the simple POCO object that will be used to transport the data. This is essential to define first so that you do not get caught up in data structures, but instead define the data as the application is going to need it. In the case with my database, I have a table called “Avail” that contains a ton of foreign keys to a contact table. I needed to display this data, but instead of a bunch of foreign keys, I needed to display the actual names of people. etc. I ended up defining the ob

Showing System message to user when logging in

As part of my role at my company, I’m responsible for deploying code to servers as well as troubleshooting issues with environments as they come up. As a result of this, I’m typically logged into multiple servers at a time. As anyone who does this sort of thing knows, it can be very easy to forget which environment you are in and accidentally modify the wrong server at the wrong time. If this happens to be a production server, the consequences can be catastrophic. Here is a nice little trick I use to make sure that people know which server they are accessing. Remote desktop into the server and open Windows Task Scheduler: On the right hand side in the Actions pane click "Create task:" When the Create task window opens, on the General Tab enter a name: Click on the Triggers tab and click the "New..." button On the New Trigger window, select "At Log on" in the Begin the Task dropdown and make sure "Any User" is selected in the Settings

Entity Framework -Revisited

I'm starting a new project soon for a new client and I've finally had some time to do some prep work to set up the skeleton of the solution/projects as well as investigate some "new" technologies. One of the things that I've revisited is Entity Framework(EF). I thought a great way to get my blogging going again was to post my thoughts on EF. <gasp> Turns out is not as bad as I thought it was... </gasp> Why I hate(d) Entity Framework: Until 4 weeks ago, I was not a fan of EF. This hate of EF was born out of early adoption of the technology (V1.1) and attempting to implement this in an N-Tier Application. The pain points were many and there were numerous times when we almost put the project on hold for a week while we ripped out all Entity Framework pumping and re-laid L2SQL  Each time the pain of doing so seemed to out weight the benefits and then 2 days later we would uncover something ELSE that would make EF seem even worse. This would then forc