Filed under: ASP.NET

Microsoft Poster Links

I was recently searching for links to many of the Microsoft Posters that are available in PDF format.  These posters are usually very large and can be printed out either on a printer or taken to a store like Kinko's or the UPS Store to be printed on poster paper.  This list will change or get added to as I find new posters or the links change.

Posters:

  1. Exchange 2007 Component Architecture
  2. Windows Server 2008 Components
  3. TechNet Active Directory Jigsaw
  4. Windows Server 2008 Active Directory Components
  5. .NET 3.5 Namespace Poster

Again, most of these posters are meant for printing on paper large than 8.5x11.

-Brent

CruiseControl.NET GUI Config Tool - CCNetConfig

We are currently working on implementing a stronger Continuous Integration strategy at our office. Currently we have a single web application that is built a matter of seconds after something in our Subversion repository has changed. It then automatically deploys the newly compiled and hopefully "built" release to a file server for immediate testing by our BA/SA guys.

So in the process of trying to add more projects and improving what CCNet can do for us I ran across a cool little article (http://www.codeproject.com/KB/cs/Continuous_Integration.aspx) by Sean Chambers. In it he lists a lot of the popular tools that can be integrated with CCNet. One that I missed on the first read through is CCNetConfig. If you are familiar with editing CCNet config files to add projects and project settings, you know it can be a little tedious, especially when trying to remember the correct XML keys/values. CCNetConfig is a GUI that uses similar features of Visual Studio to help you setup Projects, Tasks, Publishers, and most anything you could possibly want.

It is worth mentioning that CCNetConfig can edit the CCNet Configuration file on a remote build server or machine, and thanks to ASP.NET the application pool will automatically recycle when you save and the changes are instantly put into place (NOTE: From good sysadmin standards you might not want to do this, or at least backup the original config file first).

All around this is a great tool and can save lots of time when you need to quickly turn up a new project in CCNet. CCNetConfig is available from CodePlex free of charge:

http://www.codeplex.com/ccnetconfig

Quickly Building N-Tier Apps in ASP.NET and C#

When looking for something else today I ran into a really cool site.  If you need a quick way to churn out N-Tier logic and code this site is awesome.  It will walk you through the process of building domain objects, data access layers and basic business logic.  It even creates the SPROCS for you as well.  I have not done a thorough check of the code it generates yet, however any tool that will help minimize the time to build any of this is great!

Go Here: http://ntier.inspiredeffect.com/start.aspx

Lot's of Props to Inspired Effect who put this site together it is impressive.

Adding Values to DataBound DropDownList

Ok,

This is something that is usually one of those little annoying things that needs to be done… but you're never really sure the best way to do it. So here's the scenario:

You have a drop down list for "Courier". You bind the dropdownlist to a data source or other object with type IDataSource. The problem is what if they do not select a Courier. How do you record that they have none on file? Do you create an entry in the data source for an entry like "None"? Or do you have to add it to code?

I believe that the database should hold data that is used not take up space and cause more work… even if just a little for the data base server to have to sort through. So here is my solution: Add a few lines of code to create a "None" entry and handle it in the DB.

First you need to prep the database. For our example let's assume you have a table called couriers with the columns "CourierID", "Courier", and "Abbr". In your relational table where you will store the CourierID you need to make sure it is Nullable.

The second part is to add the code that will add the "None" entry to the Drop Down List.

Note: You can use the same procedure for other List Based Controls like the Radio Button List.

We use the "DataBound" event of the DropDownList because if we try to add our item before it has finished binding the "DataBinding" event will erase all of the entries we may have added. Use the code below:

Protected Sub ddlOrgType_DataBound(ByVal sender As Object, ByVal e As EventArgs)

Dim li As New ListItem

li.Text = "None"

li.Value = ""

Me.ddlCouriers.Items.Insert(0, li)

End Sub

So let's walk through the code… We create a list item. This allows us to specify the text, value, and all of the other properties of a list item. I have specified the text and value. The last step is to add the list item to the "Items" collection of the drop down list. We simply call the Insert method. The first overload specifies the index position for the list item to appear. I want mine to be the first in the list. The second overload is my list item.

Another option is to use the "Add" method but the list item will be placed at the end of the collection.

After this is done your extra list item will appear. Now when it is selected and saved back to the database the contents would be empty/null. You would need to add a display handler to write a label or string that said no courier is selected. Something like:

IF Contents = Nothing Then

'Throw Message

END IF

Of course the decision to do it like this is purely project based. I simply wanted to provide the process for keeping the logic in code versus the database for this instance.

N-Tier Database Settings and Management for ASP.NET

Ok, so the purpose for this post is because, I myself, as well as countless others have been searching for this answer all over the net. I provide it here as a reference and resource.

Here is the situation:

  • You build an ASP.NET Web Application which is part of a Visual Studio Solution. You store your Database connection strings in your Web.Config file under the correct <connectionStrings /> section. However, in order for a true N-Tier solution in Web Applications you also have a BLL, DAL, and possibly other projects that contain your Classes and Logic for the UI layer of the Web Application. So the problem is this: how do I share my ASP.NET project's Connection String information with the DAL and other layers?

This is a simple enough idea and makes perfect logical sense, however the answer is not always easy to find. I finally sent Scott Gu and Scott Mitchell, kudos to them, the question to get the official "Microsoft" answer. As Scott explained, any Class libraries are allowed to have, as part of the project the standard "App.Config" file, basically the Windows Forms version of the "Web.Config" us ASP.NET people are used to. The App.Config file is structured a little differently than the normal Web.Config file, however it still allows for a connectionStrings setting. Attached to this post you will find a ZIP file with the sample code I use in this post.

So how does it all work?

Simple Enough:

  1. Ok first we either need to create a project or open an existing solution to work with. If you are reading this I assume we have mastered basic Visual Studio tasks
  2. The example code attached will have an ASP.NET Web Application called "WebApplication1" as well as a Class Library called "DAL". Most of the DAL work I do is all done with Datasets and TableAdapters utilizing the Visual Studio IDE and GUI, so I normally remove the default "Class1.vb" file that Visual Studio generates.
  3. Ok so first we need to make sure our Web.Config file has all of the correct information in the <connectionStrings /> section. Here is a sample:

<connectionStrings>

<clear/>

<add name="SampleConn"

connectionString="Data Source=MyDBServer;Initial Catalog=Sample;Integrated Security=True"

providerName="System.Data.SqlClient" />

</connectionStrings>

 

  1. So now the task is to setup the equivalent in our DAL class library. To do this we need to "Add" the Application Configuration File. The default name is "app.config". Just like our web.config file it is pre-populated with settings. You can leave them, they are ok.
  2. Now the fun part: we need to add the connection string parameter to the app.config section so that our TableAdapters have something to look at. But wait! How does this work, how will the TableAdapters know to look at the web.config and not the app.config you ask? Magic, seriously… when you finish with your solution and build the applications, the Classes are compiled into Classes, as long as you get the naming right, which we will describe below, then the "app.config" file for an ASP.NET Web Application is the "web.config" file. So as long as the name of the connection string matches then the Class Libraries could care less about whether it is named web.config or app.config.
  3. So here is the "app.config" code:

<connectionStrings>

<clear/>

<add name="DAL.My.MySettings.SampleConn"

connectionString="Data Source=MyDBServer;Initial Catalog=Sample;Integrated Security=True"

providerName="System.Data.SqlClient" />

</connectionStrings>

 

  1. Notice that the "name" for the connection string is actually the physical namespace for the app.config file. This is required! Make sure that you specify the name based off of the Namespace specified in your project settings for the Class Library. If your root namespace was Samples.DAL then the name should be "Samples.DAL.My.MySettings.SampleConn"
  2. Ok, that's it. Build your project and make a change to your web.config file. Notice the data is no longer connected? This means everything worked!
  3. Good Luck!