Monday, January 07, 2013

What to do when you are locked out of SQL Server

I was recently helping out a fellow Headspringer when we realized we were locked out of his local SQL Express installation. We just needed to start SQL Server in single-user mode, give rights to whatever users we want, and then start back in normal mode. Here’s what we did:

  1. Launch SQL Server Configuration Manager
    CropperCapture[2]

  2. Stop SQL Server (SQLEXPRESS) instance
    (To stop: right-click stop or click then click the stop icon)
    CropperCapture[3]

  3. Go to the properties of SQL Server
    (To get to properties: right-click click properties or click then press alt+enter)
    CropperCapture[4]

  4. SQL Server 2012
    Click “Startup Parameters” tab and enter “–m” then press Add, Apply, and close the window
    CropperCapture[5]

    SQL Server 2008/2005
    Unfortunately I don’t have a screenshot of the 2008 or 2005 properties window, but I believe the startup parameters is under the advanced tab and make sure to add separate the parameters by ; (this bit me the first time around)

  5. Start the SQL Server (SQLEXPRESS) service
    (To start: right-click and click Start or click then click the start icon)

  6. Run SQL Server Management Studio
    (To start: win+r and type ssms press enter)
    CropperCapture[6]

  7. Connect and add the BUILTIN\Administrators or whatever users you prefer to add

  8. Remove the –m startup parameter
    1. Stop SQL Server
    2. Open Properties
    3. Remove Startup Parameter
    4. Start SQL Server
    5. Good to go

View more at microsoft.com

kick it on DotNetKicks.com

Friday, October 12, 2012

Building a Feature Branch Configuration Template in TeamCity

I don’t know about you, but sometimes we have frequent feature branches on our projects. Sometimes we don’t go through the trouble of setting up a build configuration in TeamCity if it’s a quick feature, but sometimes we like to see the pretty green checkbox in TeamCity when our build finishes successfully…especially when more than one person is working on the feature. We also like to deploy straight to our testing environments from a feature branch occasionally for testing, so it’s important for adding a build configuration quickly and accurately in TeamCity. I thought I’d give a demonstration on how to create one.

There are two ways to make a template. From scratch and from an existing build configuration. I will not talk about the “Extract Template” option because it’s literally clicking a button and giving a name from within the “Edit Build Configuration” screen. However, there are two things you’ll need to look at in order to use the extracted template as a feature branch template. So look at steps 2 and 4 below for the details if you have an existing build to use as a template.

Step 1: Click “Create template” under “Edit Project Settings” (I’m using version 7.0.4 of TeamCity btw)

CropperCapture[1]

Step 2: Fill in the name…I called mine Feature Branch Template (original I know). If you have a different build number per feature branch, which we do on this project, you can put %BuildNumber%.{0}.0 for the “Build number format”, otherwise, just leave it as the default (like below). Specify your “Artifact paths”, ours usually looks something like “build\latest\*.zip”. Click “VCS settings”.

CropperCapture[3]

Step 3: Here’s where the fun comes in…click “Create and attach new VCS root”.

CropperCapture[5]

Here you will select your VCS and fill in the appropriate information. The only VERY important thing you need to do is input “%BranchName%” into the Branch name. What this does is creates a parameter that will be required by your build configurations that use this template. Obviously we are using Mercurial, but you would just do the same as above for the equivalent of a branch in your source control.

CropperCapture[6]

When you’ve completed filling out the required information and tested the connection, Save. (Pro Tip: Don’t put %BranchName% in that field until after you’ve done “Test connection” with a real branch name.)

You should see this after saving:

CropperCapture[7]

Step 4: I’ll just leave all the defaults on the “Version Control Settings” screen, but if you require any of those settings, please set them if they apply to all your feature branches. Click “Add Build Step”.

CropperCapture[8]

Step 5: Configure your build steps. We only have two steps because we use psake…so basically we call the build.bat in our repo root with specific params and the other step just runs our unit tests with coverage.

Step 6 (optional): Configure fail conditions if needed…the most common condition I’ve seen is looking for specific text in the build log.

Step 7: Configure Build Triggering…we use the VCS Trigger, which detects when code is checked in. After clicking “Add new trigger”, you should see this:

CropperCapture[9]

I just use the default values. Click Save.

Step 8: Click Build Parameters – You should see BranchName <value is required> and BuildNumber if you specified that one in step 1.

If no BuildNumber specified:

CropperCapture[11]

If BuildNumber specified:

CropperCapture[12]

Okay, you’re done. Now you can start using the template…here’s how:

Under “Edit Project Settings”, click “Feature Branch Template”. In the bottom right, you should see this:

CropperCapture[13]

Step 1: Click “Create Build Configuration from Template”

Step 2: Give it a name…typically I name it the branch name.

Step 3: Now click Build Parameters on the right

Step 4: Click the <value is required> for the parameters you specified above and set the value. Click Save.

You’re done.

The way we were handling this before was by copying the build configuration and then creating a new VCS root with the appropriate branch name and add to remember to change the build number…now it forces us to tell it and we don’t have to create the new VCS root.

Please provide any feedback or post a comment if you have any questions.

kick it on DotNetKicks.com

Sunday, September 23, 2012

Export to Excel with MVC

I’m sure you’ve all had to export to Excel at one point or another. I created a small wrapper around the EPPlus library for MVC. Basically my wrapper contains a few helpers for common formatting, an ActionResult, and a column definition. Here’s what the end result looks like in the simplest form:

Basically this exports all the columns and records in the SampleInfo collection. So if you want to specify the columns you want, you can do this:


The ExcelColumnDefinition.Create<> is kinda ugly, so you could create a small helper method for readability like this:


Now the above example looks like this:


So this is what the ExcelColumnDefinition looks like:


Here’s the actual ActionResult:


So that’s it. If you have any questions, please feel free to comment below.

You can browse or download the source on GitHub. The sample project has examples.

Shout it

kick it on DotNetKicks.com

Thursday, August 30, 2012

Simple Way to Toggle on Hover with CSS

Here’s a really simple way to toggle actions or more information to keep your pages clean.


View Demo

kick it on DotNetKicks.com

Saturday, August 25, 2012

A Method for Populating a Dropdown List in ASP.NET MVC

I’m asked quite a bit how to bind a dropdown list in ASP.NET MVC. So there are about 10,000 ways to do it, but here’s one.

First, we’ll create a simple interface to return a list of SelectListItem so we can use the built-in DropDownListFor() later on.

Then we can create a SelectListProviderAttribute to take in the Type of list provider we want. You can see in this example I'm instantiating the object with StructureMap...you could do this with Activator or something else.




Now we just implement an ISelectListProvider and add the attribute to our model like this:

Sample property on view model:
[SelectListProvider(typeof(CommunitySelectListProvider))]
[DisplayName("Community")]
public int CommunityId { get; set; }
Now we just call our new HtmlHelper in our view and we're done. So here's the helper:


And now we just call it from the view like this:

@Html.DropDownListFor(x => x.CommunityId)

I'm sure you all realized that I used some additional helpers in code samples above. So for the curious few, I uploaded the full sample project to github. Browse the source now

Shout it

kick it on DotNetKicks.com

Tuesday, July 31, 2012

Dynamically Generate Form with jQuery and ASP.NET MVC

Hopefully it’s obvious that you probably won’t need to do this very often, but when it’s needed, it’s nice to have available. I thought I’d share this little helper to dynamically create a form, append it to body, and submit it...without AJAX.

First I'll show you how I'm converting my view model to a parameter list and a query string. Basically I've created an extension method that loops through properties and checks if it's an IEnumerable or not. If it is, then I loop through the values of that property. Otherwise, I just add the value. This method does not work with complex types. Typically view models are flat, so this works well most of the time.

The ToQueryString method just calls the ToParameterList, adds a ? to the front and then just selects what it needs from the parameter list.

The jQuery is pretty straight forward. I get the body, create a form with an action, loop through my param list creating a hidden input for each param, append the form to the body, and then submit it.


As always, if you know of a different and/or better way, please let me know.

If you don't need to post, you can just use a get, you could do something like this:


You can download a sample project at GitHub.

Shout it

kick it on DotNetKicks.com

Monday, June 11, 2012

Making Prettier Forms: Converting Checkboxes into Images

A couple weekends ago I went to the Big Design Conference in Dallas (recap coming soon), and I always come back inspired to help the user’s experience with the applications I write. One of the things mentioned (several times) was making forms simpler. Basically, you don’t have to make the end-user feel like they’re filling out a form. There are ways to make it seem less intimidating. One way is to swap out the typically hard-to-click checkbox or radio button with an image. It gives the user a larger click area and it looks nice…at least in my opinion.

Basically, I’m helping a friend with a small project, and the image below is what I wanted to create.

image

If you buy Stephen Anderson's book "Seductive Interaction Design", you will see a similar form to the one above...primarily just the name and contact info stuff. By the way, I definitely recommend this book.

As you can see, the “Select Classification” is not your typical radio button setup. I googled for a bit if there was already a jQuery plugin to do this type of thing and came up empty. I’m sure you almighty readers know of one, but I couldn’t find it…so I made one.

So far I’ve tested it in Firefox, IE9, Chrome, and JAWS, and it works pretty good in all of them. The way I set it up to work is based on the input and label. So you’d have the most accessible standard markup with your preferred styles for the label, and that’s how you get the effect shown above. I think it’s probably better said with code:

So it looks like a pretty typical setup so far, right? You have an input with a label. To make it more accessible, you wrap it with a fieldset and give it a legend. The primary reason you’d do this is to give screen readers some context. If you don’t need to worry about that, you could just as easy wrap it all with a div. You’re going to want to wrap it so your jQuery selector is more precise. After you markup the form, you just add the following JavaScript.

Now you’re all wired up, and you just add in your styles to whichever stylesheet classes you specified. The default stylesheet class names I specified are:

  • .Selected-Checkbox – this class is added to the label after it has been clicked
  • .Checkbox-in-focus – this class is added to the label when the checkbox/radio button is in focus

If you’re not sure the plugin is working properly, you can put it in “testMode”, like this:

$('#classification_radio_wrapper label').checkMate({testMode: true });

If you need to override my default class names, you can do that too by specifying class or focusClass in the options. I might rename class to selectedClass in the near future.

Please leave a comment if you have any questions or feedback.

The source code is available on github at https://github.com/derans/checkMate

The demo is located on 1pg.it at http://1pg.it/v9etvtn5 (also on github as the example.htm file)



Shout it

kick it on DotNetKicks.com

Related Posts Plugin for WordPress, Blogger...