CodersBarn.com
The ASP.NET Community Blog

New MSDN Code Gallery

March 3, 2008 14:04 by agrace

Are you looking for some free code samples? Microsoft recently launched the MSDN Code Gallery. It differs from the CodePlex site in that it is more geared towards developers who are starting out. It is a true community site where you can create your own resources page in the shape of a wiki and share your own code samples with the community. You can keep it in edit mode for 30 days before sharing your code masterpieces with an unsuspecting public ;-)

I had a surf around the new site and came up with a gem of a new tool for Visual Studio 2008. It's called StickyNotes and it is a Visual Studio package that provides sticky notes capabilities to project and project items inside Visual Studio 2008.

StickyNotes

This is so much neater than the standard Task List that comes with VS, although I can see myself using both. StickyNotes is ideal for jotting down reminders of things to do at a file level. I usually load my code pages with comments in the early stages of a project and this tool is sure to free up my code files. Thanks to Pablo Galiano for this wonderful new tool :-)

kick it on DotNetKicks.com


ASP.NET 2.0 Guest Book Admin - Part II

February 24, 2008 07:32 by agrace

Guest Book Solution You can also view part I of this article which describes the setting up of this application with Visual Studio 2008 and IIS 7, running on Vista. SQL Server 2005 was used as the database. I had originally blogged on this using VS 2005 but feedback indicated that quite a few people are now using VS 2008, so I upgraded it to VS 2008, which I am currently running on VMWare Workstation... the best $190 I ever spent. This is part II and the full code will be available for download in part III, real soon!

Speaking of feedback, I have been having problems with the comments system on this blog for some time now. So, pretty soon I am upgrading the blog engine and switching to a database version. The plan is to eventually make it a real "Community" site. Watch this space...

The Guest Book application is written in C# and is pretty straightforward. Here I will walk through the creation of the back-end which will allow the site administrator to moderate the comments posted to the guest book by site visitors.

First, we need to set up our membership system. The membership system is where most people seem to get stuck. There are several ways of achieving the same thing and I think that this is what causes much of the confusion. Typically, in an application such as this you would use a CAPTCHA control to combat the spammers, so we are not going to force users to register in order to sign the guest book. We will need an administration area for our admin forms, so we will create an "admin" role. The way I go about this is to create a new folder and call it Admin. Add a config file  to this new folder and set up the authorization rules as shown below.

Admin Web.config

Now, we're going to cheat a little. I'm going to do the TV chef and slip in a little something I pre-prepared earlier in the kitchen (actually gleaned from several of Scott Guthrie's blog postings). I always keep a sample Web.config file handy that I know is set up correctly for a basic membership system. I start this way rather than jumping in right off with the WSAT wizard because I want to have one single database for both my application and membership data. Tidier. So, I manually set up the database connection in the project Web.config file, along with entries for the membership and authentication sections. See the snippets below, and don't forget to include the roleManager tag!

Project Web.config

Now that the membership database connection is configured the way we want it, we can run the aspnet_regsql tool from the command line. This will create the actual membership database objects for us as part of our Guests database. Just navigate from the start menu to SQL Server Management Studio and locate the command line tool under the Configuration Tools folder. Simply enter aspnet_regsql at the prompt and you will be presented with the SQL Server Setup Wizard. Here are some screenshots showing the correct selections to make:

SQL Server Setup Wizard

SQL Server Setup Wizard

SQL Server Setup Wizard

If you go to SSMS and refresh the database, you should now be able to expand the tables icon, and you will see that the wizard had created everything we need for our membership system. At this stage, you are ready to run the WSAT tool and start setting up the admin role and adding the admin user. I will outline this process in the final installment, as well as the creation of our administration forms. Stay tuned!

Membership Database Objects

kick it on DotNetKicks.com   PHP, ASP, .NET, JSP Resources, Reviews


End of the Impedance Mismatch?

July 10, 2007 17:37 by agrace

On a practical level, yes. And with a rack of new technologies in the offing from Microsoft, we are sure to have a far more enjoyable programming experience in the near future than we have had up to now.

For almost three decades, object-oriented programmers have had to deal with the impedance mismatch issue. In essence, the programs we use to access our databases are object-oriented while the databases themselves are relational. There is not a direct mapping between them. And while much of it is fairly obscured through the use of the ADO.NET API, it would be fair to say that the two models are as similar as chalk and cheese.

In middle to large-sized projects, we typically use entity objects as object-oriented views of our relational data. The biggest problem has always been establishing the mapping between the two. This often entailed the use of third party tools such as NHibernate. An alternative approach was object-relational databases which I never did like.

Enter the Magic Triumvirate of LINQ, Orcas and the Entity Framework! This set of technologies promises to eliminate the impedance mismatch between the various data models and programming languages. With LINQ, we now have rich queries built right into the language and can access the data source whether it's XML, relational or objects. Orcas, the latest version of Visual Studio is currently available for download as a CTP release. The best bet may be to install the virtual PC version. I'm planning on doing this myself this weekend as I really want to get the feel of the new LINQ syntax. The only sour note in all of this is that the final version of Entity Framework won't be available until after the Orcas release. In the meantime, you can download the new CTP version of the Entity Framework.

Here's a simple LINQ query taken from 101 LINQ Samples:

public void Linq()
{
  List products = GetProductList();
  var productNames = from p in products
    select p.ProductName;
  Console.WriteLine("Product Names:");
  foreach (var productName in productNames)
  {
    Console.WriteLine(productName);
  }
}