Web.Config Issues Deploying .NET 4.0 MVC2 Site To IIS7

In .NET 4.0 they cleaned up a lot of the configuration elements for a web site’s web.config and moved it the the frameworks machine.config.  This has greatly streamlined the web.config.  The other day I was deploying a MVC2 site running under .NET 4.0 to an IIS7 web server and received a configuration error stating “There is a duplicate 'system.web.extensions/scripting/scriptResourceHandler' section defined”.  It turns out that MVC2 project template comes with come web.config settings which work under .NET 2/3.5, but are redundant in 4.0.  In order to fix this, remove the following settings, the type attributes have been removed for brevity.

<sectionGroup name="system.web.extensions" ...>
<sectionGroup name="scripting" ...>
<section name="scriptResourceHandler" .../>
<sectionGroup name="webServices" ...>
<section name="jsonSerialization" .../>
<section name="profileService" .../>
<section name="authenticationService" .../>
<section name="roleService" .../>
</sectionGroup>
</sectionGroup>
</sectionGroup>

See ASP.NET 4 Breaking Changes for details on breaking changes in .NET 4.0.

Find jQuery Autocomplete Input ID

The other day I was working with jQuery autocomplete where the autocomplete was being applied to a collection of input elements.  One of the issues I was running into was that I needed a reference to the input that the automplete was extending during the execution of the select event.  The way to do this is to store a reference to the input inside the function executing the select event, in essence create a closer.  Below shows how this done, the call to $(this) resolves to the input that is being autocompleted.

$(".all-my-autos")
.autocomplete({
source: "auto-me.php",
minLength: 2,
delay: 500,
select: function (event, ui) {
var input = $(this); // reference to input
// do what you need with input...
alert(input.attr('id'));
}
});

Visual Studio 2010 Javascript Outlining Plugin

The other day my colleague Ben Martin, a somewhat developer tool aficionado, sent me this great JavaScript enhancement plugin for Visual Studio.  I’d have to say, it is one enhancement I’m surprised was not already in Visual Studio.  The plugin adds outlining and minimizing/maximizing code blocks, the same that you would get in a C# code file.  It is a much needed enhancement and a must for anyone who is doing JavaScript coding.  I think the only thing I noticed that would be nice to have in it would be the Ctrl+M+O hotkey which minimizes all code blocks.  You can download the enhancement here.

Getting Started With Eclipse And Team Explorer Everywhere

In a previous post, Install Team Explorer Everywhere 2010, I covered the installation of TEE, so now I’m going to cover connecting to a TFS team project collection. 

1.  To get started open the Team Foundation Server Exploring (TFS Explorer for short) perspective, this can be found in Window ^ Open Perspective ^ Other…clip_image002

Now your current windows should look like the screen shown below.  The icon used to add a TFS server connection is circled in red, which will be used in the next step.  If you’ve used TFS with Visual Studio, you’ll notice that the layout is nearly identical to what it is in Visual Studio.

clip_image002[7]

2.  To add the TFS server, click on the icon that is circled in the previous image. The “Add Existing Team Project” dialog will appear. This is where you add your TFS server (see image below). The advanced tab allows you to port settings, for example if you’re using SSL. Enter in the correct server URL, the default would be http://{server}:8080/tfs. Click Next.

clip_image002[9]

3.  Continuing from the server setup, you should be on the Team Project selection page. On the left pane is the team project collections list. Prior to TFS 2010, there could only be one project collection. On the right pane are the team projects within the collection. Select the team projects that you want view. Click Next.

clip_image002[11]

4.  Once it finishes querying TFS, the last window will appear showing any workspaces you have. Here I have one because I already created a workspace through Visual Studio. Select your workspace and click “Finish” if you have one else continue with this step to create one.

clip_image002[13].

If you don’t have a workspace defined, you can create one by using the “Add…” button. You will see the workspace dialog appear as shown below. By default the workspace name will be your machine name. In the working folder you must map a source folder to a local folder. In the Status column select Active from the options. In the Source Control Folder option, click the browse “…” icon to bring up the TFS source “Browse for Folder” dialog. Select the source path you want and click Ok. Now in the Local Folder column, select the browse “…” icon to pick local file path where you want the source to copy down to. Once done you can click Ok to finish creating workspace.

clip_image002[15]

5.  Now the Team Explorer should be filled in and some more sub-windows should appear (see image below). With a team project expanded double click the “Source Control” item, see red circled item. This will display the Source Control window. Below highlights the 3 main windows that I use on a regular basis.

    • Team Explorer: Contains a list of team project collections, and under each collection is a list of team projects. Items will show up based on what you have selected in your workspace.
    • Source Control: Shows a folder tree display of all available branches to you. Navigating these you will be able to see whatever you have checked in to these branches.
    • Pending Changes: This shows a list of any pending changes that you have checked out. You can also check the items in from this pain as well, shelve/unshelve, associated check-in with work items, etc.

clip_image002[17]

 

And that’s it, you are now ready to check in/out your project files to TFS and take advantage of the integrated features of TFS such as bug tracking and shelvingShelving is a neat feature of TFS that allows you place your code on a virtual “book shelf” with some name so at some later date you can retrieve this named “book” of code from the shelf.  This is very useful if your working on a large feature and you have files checked out for more than a day.  At the end of the day you can shelve the code, which stores your changes on the server.  If your machines dies for some odd reason, all your hard work is not lost.  You can also share you shelved items with other team members.  For details of shelving see, Walkthrough: Shelving Version Control Items.

Running Database Project Deploy Script In SQL Management Studio

Visual Studio Database Projects is a great way to manage and maintain your SQL server database schema.  The projects offer compile time checking just like any other code type project would.  When you build build the project you have the options of either creating a deployment script or a script plus deploy it to a given database instance.  If you create the script, there is one caveat that I find myself forgetting the first time I run it via SQL Management Studio, setting the SQL command mode.  This is necessary to resolve the lines that start with “:”, such as “:setvar”.  To enable the script to run successfully, open the menu Tools ^ Options.  Click the “Query Execution” in the list.  Check the “By default, open new queries in SQLCMD mode”.  Open a new query window and run your script.

temp

Executing Stored Procedure With NHibernate

There are two reasons why you might want to execute a stored procedure using NHibernate.  The first would be for your normal CRUD activities which can be found here, Populating Entities From Stored Procedures With NHibernate.  I’d like to focus on the other scenario you might find yourself needing to execute a procedure, like running a complex report or some query that is better performed in a procedure.  The real benefit of NHibernate is that you’re not coding to an implementation but to a set of interfaces.  This buys you the blissful ignorance of the underlying database vendor, see also my post on NHibernate And Paging Results.

Executing a procedure requires two main items, a connection and a command object.  The connection comes from the session, and the command comes from the connection’s method CreateCommand.  Below shows a very straightforward way of executing a procedure.  Notice that the connection and command objects are just interfaces from System.Data namespace.

List<SomeDto> list = new List<SomeDto>();

using (ISession session = NHSessionManager.OpenSession())
{
// use the ISession to get the database connection
IDbConnection conn = session.Connection;

// use the connection object to get the database command object
IDbCommand cmd = conn.CreateCommand();

// set the command text to the procedure's name and set the command type
cmd.CommandText = "dbo.MyAwesomeProcdure";
cmd.CommandType = CommandType.StoredProcedure;

// using the command object you can create a parameter, setting it's properties accordingly
IDbDataParameter p;
p = cmd.CreateParameter();
p.DbType = DbType.Int32;
p.ParameterName = "@someParam";
p.Value = someParamValue;
cmd.Parameters.Add(p);

// data read to capture results
IDataReader reader = null;
try
{
reader = cmd.ExecuteReader(CommandBehavior.SingleResult);
while (reader.Read())
list.Add(new SomeDto
{
Name = reader.GetString(0),
Age = reader.GetInt32(1),
...
});
}
finally
{
if (reader != null)
reader.Close();
}
}

return list;