The future of .NET, Visual Studio and more

May 24, 2008

Last year I blogged about Microsoft SOA initiative “Oslo” and the first mentions of .NET Framework 4.0. Today I decided to try to find more information about what the future in the Microsoft development world will hold.

As the information has been quite minimal, I decided to find out what kind of job postings Microsoft has listed at the moment as they reveal something of what they are planning at the Redmond. As it turns out, there are lot’s of interesting things coming in the future versions of .NET Framework, Visual Studio, SQL Server and SharePoint.

It should be noted that the information in this post is based mostly on combination of several job listings and speculations and it shouldn’t be taken as a definite road map or truth. Projects can be combined, canceled and delayed. I’ll link to the original job posting sources, but I’m not sure how long the links will work.

.NET Framework

This job post reveals how there will be several SKUs of the .NET Framework:

You would work with the .NET Framework teams in proactively identifying/consolidating redundant feature areas and in driving the core framework technologies. One of your immediate roles will be in helping us factor the .NET Framework to be more flexible, by building the right set of runtime features, such that we can ship multiple .NET Framework SKUs in an agile manner. For example, we must reach the right layering and componentization goals to ship a nimble form factor, such as the .NET SilverLight Framework (for web client) and the .NET Compact Framework (for embedded devices), then build it up to the .NET Client Framework (for rich clients) and ultimately to the full .NET desktop client (for client/server). You would establish framework life cycle, with a particular emphasis on removing obsolete features, so that we can advance the platform futuristically. You would also closely work with Visual Studio architecture team in enabling a flexible multi-framework-targeting experience.

Source

These days .NET Framework distributable is quite large so this was also bit expected to happen at some point. I recall reading from Scott Guthrie’s blog about this earlier. It should also be mentioned that VS2008 SP1 will bring “.NET Framework Client Profile” as mentioned in ScottGu’s post.

Web Development, SharePoint, IIS

Apparently some sort of media server product for Silverlight is in the works:

Do you want to help drive the technical strategy around Web and Media technologies that will shape the internet? Do you love deep, pragmatic, and focused engineering challenges where you control the schedule? Have you ever wanted to drive a small, start-up engineering team building a code base from scratch?

The .NET Developer Platform team is looking for a Group Manager to build Microsoft’s new media server product. This team will deliver the server-side media infrastructure and services required to stream rich media on the Web and work hand-in-hand with Silverlight running on the client. We are looking for a Group Manager who can lead a small team of 10-15 engineers to build this code base from scratch, as an integrated part of the new Web and Media platform.

Source

Now this is getting more interesting. It remains to be seen, if this will be a free add-on for IIS or a commercial product.

Moving on to the SharePoint:

Would you like to be part of the newly formed team whose charter is to develop a v1 infrastructure and tools for SharePoint platform? Would you like to invent, design, and influence a wide range of RAD developer tools for the fastest growing server product in Microsoft’s history? Would you like to work on a team that is in the early stages of execution, designing a new revolutionary set of tools? If so, the Developer Division Business Applications team is the place for you.

Our mission is to empower professional, departmental, and end user developers to create a complete range of business solutions and customizations on the SharePoint. We are part of the Visual Studio family. One of our vNext deliverables includes a rich tool set to support Microsoft Windows SharePoint Services (WSS) and Microsoft Office SharePoint Server (MOSS) that enable developers to fully utilize Visual Studio and the .NET Framework as a development platform.

Source

The last paragraph is the interesting part. Anyone who has developed custom solutions on MOSS 2007 knows that it can be a nightmare. While it has a good collection of components and services, the development and deployment experience could be a lot better. I personally prefer plain ASP.NET projects as the development life-cycle is much more enjoyable and more risk-free. Hopefully these tools will make the SharePoint vNext development much more enjoyable.

This is also very interesting as it seems to unify ASP.NET, AJAX and Silverlight development:

Are you interested in delivering a cutting-edge technology that will revolutionize Microsoft’s developer platform? Are you looking for the opportunity to help drive several of the key value propositions of the next release of Visual Studio and the .NET Framework? The UI Framework and Services team – part of the .NET Developer Platform group, and owners of ASP.NET, ASP.NET AJAX, and Windows Forms – is kicking off a new project that will be at the heart of the developer experience for building Rich Internet Applications on Microsoft’s .NET Client platform. The goal of the project is to deliver a dramatically productive and simple experience that enables RIA developers – a key developer market – to easily build rich and powerful data-driven applications on .NET. The project will build on the huge customer excitement in Silverlight and WPF, and the success of ASP.NET, to deliver an unparalleled client developer story. The key value propositions we will deliver on are:

  1. A complete RIA platform
  2. An application model that vastly simplifies LOB application development
  3. Greatly simplify N-Tier app development
  4. Seamlessly take your RIA out of the browser

To assist us in this project, we are looking for a strong and experienced SDE to help drive our Application Model and Services team. This team’s challenge will be to deliver an application model that makes it dramatically simple for developers to build a rich, occasionally connected, n-tier application. Team deliverables will include a new deployment model that can seamlessly take .NET-based Rich Internet Applications from the browser to the Windows desktop, a framework library that makes it incredibly easy to deliver rich occasionally connected user experiences, and a set of application building blocks like authentication and personalization that reduce the time to build rich application functionality, and integrate Rich Internet Applications with Windows, IE, and Office.

Source

And another related post excerpt:

To assist us with these efforts, we are looking for a strong and experienced SDE to help drive our UI and UI Framework team. Building UI from data is at the heart of virtually every LOB application, and the team will deliver a set of rich Silverlight based controls, including a data grid, that enable new data experiences. The team will also deliver a programming model experience that makes it incredibly easy to build rich data-driven UI and visualizations. Building on innovative technologies such as Silverlight, LINQ and WPF, this team’s work will allow developers to very easily build a fully functional UI application out of data. Using the UI Framework, developers will be able to then easily customize and enrich the application by adding functionality such as navigation, editing, and validation.

Source

This isn’t a big secret, but it was news to me:

Our goal this year is to get Ruby on Rails working in IronRuby. You will be expected to work on the compiler, Ruby libraries, and performance improvements. We also want to provide IronRuby support in the Visual Studio IDE. This includes editing features (color-coding of source code, intellisense, etc), debugging features (breakpoints, data tool tips), ensuring a Ruby look-and-feel (interactive console, etc), and integration into the Visual Studio project system.

Source

Visual Studio

Major changes are coming to Visual Studio (some day):

Over the next few years we plan to modernize and/or re-architect various areas of the [Visual Studio] platform where we see the greatest potential opportunities for improving the developer experience exist. These include creating a new User Interface that takes advantage of the latest in UI tools, techniques, and hardware; a robust extensibility model that helps 3rd parties extend and enhance the VS environment to improve developer productivity; an editor that is both modern and extensible and greatly improves developer code understanding; a build system that can scale to projects as large as building the Windows Operating System; and an automation model that makes it easy to automate the development environment and allow for tasks like nightly builds to be automated.

Source

Another posting reveals that WPF is one of the “latest UI techniques”:

Major initiatives for this team for the next release of VS include:

* Work with the Shell UI team to migrate portions of the VS Shell to WPF

Source

Visual Studio Team System

I have just adopted Team Foundation Server 2008 and other Team System features so I’m very excited to see what’s happening on this area. Here are some finds:

If you use Visual Studio or any other popular IDE to write code in C#, C++, VB, Java, etc. then these services are a familiar part of your development lifestyle. If you develop for any of the major SQL platforms, then the available development tools leave you relatively out in the cold. In certain respects, database development tools are fully three decades behind the curve!

Come work for the team that is changing this with a market-shifting database development project system within Visual Studio. The mission for the team is no less than to bring tooling-support for database developers to par with that of traditional languages such as C# and C++, for the complete application lifecycle. This is a challenging charter, in a fundamentally unique problem-space. In one team you will find a broad spectrum of software development challenges from designer and user interface work, to the nuts and bolts of language parsing and cutting-edge code-modeling.

Source

Interesting and I have no idea what it could be in practice. ;)

Testing will also get more tools in the VSTS:

In the Rosario release of VSTST we have the ambitious goal of fundamentally changing the relationship between Development and QA by providing tools and workflow that make testers first class citizens in our customers’ development process. To do this, we will deliver world class Test Case Management, Test Authoring, Automation Tools and Frameworks, as well as game changing integrations within Visual Studio Team Suite.

Source

Distributed Applications

These days I do integration projects and distributed programming is part of my daily life. That’s why I’m increasingly looking into WCF, WF and BizTalk as they could be part of our integration product. After reading these posts it seems that something interesting (that is, Oslo) is on the way:

Join the Connected Framework (CFx) team and help us create the programming model central to Microsoft’s next generation of the distributed application framework. The team has recently delivered first versions of WCF (aka Indigo) and Windows Workflow, which are receiving significant customer acceptance. WCF is THE Web Services stack for Microsoft, and Windows Workflow is THE foremost declarative, process model framework. Now is a great time to join the team as we are starting to work on the next major release that consolidates and enhances these two powerful yet simple and elegant development frameworks into a single unified platform aiming for 10x productivity increase in distributed applications development.

Source

For the last few years, we have been on a mission to make the usage of transactions simple, fast and ubiquitous. We have made tremendous progress so far. The Systems Transactions namespace in .NET 2.0 made transactions far easier to use, with dramatic improvements in performance. We have extended the reach of transactions all the way from web services to the kernel. We authored and implemented the WS-Atomic Transactions standard. In Vista, we integrated our transactions stack with the transacted file system and registry! In Oslo, we are planning to add distributed compensation support by adding long-running transactions support to the connected framework runtime! But all of this is just the beginning. In our upcoming releases we will continue to extend our reach, from atomic transactions to long-running activities with compensation to generic agreement protocols! We will continue to make it easier to write reliable and consistent distributed applications. Most importantly, we will continue to ship regularly to get our work into the hands of customers.

Source

SQL Server and Data Programmability

Do you have a passion for building state-of-the-art graphics software? Would you like to influence the direction of a key technology used across multiple Microsoft products?

We are seeking a Lead Software Development Engineer to drive the architecture, design, and implementation of rich data visualization components – including charts, gauges, maps, and calendars – that will be included in upcoming releases of SQL Server, Visual Studio, and Office. In this highly visible leadership role, you will be responsible for managing a high performance team of software developers using the latest Microsoft technologies, including C#, ASP.NET, AJAX, Silverlight, and WPF.

Rich data visualization capabilities are quickly becoming a requirement for modern business applications. The SQL Server Reporting Services team is on the cutting edge of this technology, creating a set of powerful and interactive data visualization components for application developers, IT professionals, and end users. We are a growing team that is passionate about creating the most comprehensive database reporting, data visualization, and notifications platform in the industry. We have an expanding customer base that has ever-increasing demands for more capabilities, and we are continuing to extend our product reach, evolve the feature set, and deliver new customer innovations.

Source

Those data visualization controls will be welcomed. :)

XML tools for SQL Server/Visual Studio will be enhanced. Interesting point is that WPF and Silverlight will be part of it:

Help build the XML Editor, XSLT Debugger and XML Editing platform for developers. The Data Programmability (DP) Tools product team is a new and growing product unit that is looking for a talented and motivated developer. We want you to help define and build state of the art tools that are distributed as part of Visual Studio and SQL Server and are used by millions of developers world-wide – hobbyists and enterprise developers alike. We value and encourage innovation and excellence in graphical tool design, usability, infrastructure, and execution. SQL Server is investing in tools. If you want to make a difference and work with state of the art technologies such as WPF, Silverlight, MEF/MAF, and help define tools standards for developers, then we would like to talk with you.

Source

This posting gives many interesting details about SQL Server’s future:

SQL Server is embarking on an ambitious effort to rejuvenate the T-SQL language and to embrace all the programming models in the data platform – relational, spatial, full text, xml and entities. This involves all aspects of the SQL programming surface from designing procedural extensions to the language, to improving the cursor model, to enhanced metadata discovery, to application packaging, to building a new compiler for T-SQL, to building extensibility into SQL Server. And this is just a sampling of the problems for which you will need to design and help build good solutions. In addition, this effort will require you to work on and influence Microsoft’s Data Platform Strategy.

Source

Last notes

As you can see, many interesting tools and technologies are on their way in the next few years. My research method was very random and the job postings don’t reveal much, but I’m sure that we’ll get more information in the coming months.

However, the pattern already shows that many coming features build on existing components and aim to unify the development experience by combining them in many ways.

It seems that there will be much more graphical designers, DSLs and other modern ways of generating applications. This will split the opinions as many developers prefer to code in the traditional way, but I’m sure there will be something for everybody – I probably found just a few interesting bits out of many!

From my view point the most interesting finds were:

  • UI developers will get the Application Framework(?) that combines the WPF, Silverlight and ASP.NET technologies.
  • SharePoint development experience will be tolerable, perhaps even fun.
  • Distributed developers will get the Connected Framework(?) that builds on WF and WCF.
  • Productive LOB-application tools that utilize latest UI-technologies (Silverlight, WPF) with little or no code.
  • SQL Server will get major changes to T-SQL and new XML tools.
  • Visual Studio will be enhanced in many, innovative ways with technologies like WPF.
  • Visual Studio Team System will make database development more integrated with the development process. Testing will get more tools.

Do you have any rumors to share?

kick it on DotNetKicks.com


Windows Server 2008 – Upgrade tips

February 10, 2008

Windows Server 2008 -logo

Last night I finished upgrading Windows Server 2003 to the Windows Server 2008. Here are some tips to help those of you facing the same challenge. I had some problems along the way that I could have avoided with more careful planning, but live and learn.

As I use my server only for personal development purposes, it is not that critical as a real production server would be. Anyway, good preparation makes things easier. I chose to do a “clean” installation, as I wanted to install the Windows Server 2008 to a bigger volume.

This is a long post, but if some part helps someone even a bit, it serves its purpose. I’ll cover these tips:

  1. Make a checklist for yourself
  2. Backup and copy everything to a safe place
  3. Prepare post-installation setups
  4. Check your hardware compatibility
  5. Post installation tasks
  6. Installing and configuring applications

Disclaimer: Please remember, that I’m more of a developer/software architect kind of guy than an IT professional who maintains servers full time. I just admin my own servers and desktops when I need, so not all of my tips may be the best practices.

1. Make a checklist for yourself

Before getting your hands dirty, list all the things you have to take into consideration. I used Microsoft Office OneNote 2007 to take my notes. My server is a typical web server with SQL Server so this post mostly revolves around related things.

OneNote Checklist

In the checklist I listed things like:

  1. What should be backed up
  2. What sites and application pools I have in IIS6
  3. How do I migrate databases in SQL Server 2005
  4. What other applications I have and what should be reinstalled
  5. How should I backup and restore contents in the Windows SharePoint Services
  6. Screen captures from various settings pages (IP-settings, IIS, local users, file shares)

I should have checked these things, too:

  1. What hardware the server has and is it supported
  2. Get the latest drivers for Vista and Windows Server 2003, if there are no native Windows Server 2008 drivers.

2. Backup and copy everything to a safe place

After you have made at least some plan, execute it by copying all the settings, files, databases etc to a place that can be easily accessed after upgrade.

Also, if you have some external USB drive, copy them there. I had lazily put most of the backups and post-installation setups to the backup raid that required drivers to work. If I wouldn’t have been able to get it to work, I could have been in trouble. Separate USB disk would have been safer and compatible whatever happened.

Here are some detailed tips:

SQL Server 2005: I detached the databases and attached them after installation of the new Windows Server. There were only few important databases, so this was faster way than the backup/restore -way. If you want to move your logins, scheduled jobs and other database server wide-stuff, remember to backup at least master and msdb -databases. If you do it manually like me, make sure you know or can locate the passwords for the logins that your apps. may use (connection strings etc).

IIS6: There are some tools that help migrating the database, like the new MS Deploy -tool. I considered using it, but I couldn’t install it since it required .NET Framework 2.0 SP1 that wouldn’t install on my Windows Server 2003 for some reason. So I decided to manually copy everything and configure them in IIS7.

WSS: I only use Windows SharePoint Services v3 to sync my OneNote -notebooks between work and home, which is very handy (I’ll try to blog about it later). After checking the sites and their contents, I decided that again it is easier to copy the files manually and setup the few sites I have manually.

First I considered backing them up with the stsadm, but then I noticed that due to DNS/router configuration, I couldn’t actually access the WSS from the localhost and fixing it would have taken more time than manual way for that small amount of data.

DNS server: I just copied the %systemroot%\system32\dns -folder to safe place.

3. Prepare post-installation setups

Remember to think through the whole process. Backing up the data and installing the Windows Server 2008 is only half of the process and what follows is re-installing the applications you need.

This will be much easier and faster if you reserve all the setups, service packs and product keys to one place.

If you are going to install applications from an .iso-image, you’ll need some program that can access them from the Windows Server 2008. I have been a long time user of the Daemon Tools, but over the last few years I have liked it less and less (ad-ware, reboot during installation, problems in Vista etc). I decided to try the free MagicISO, which works fine for me in Windows Server 2008.

4. Check your hardware compatibility

This may sounds obvious, but actually I neglected to do this, since:

  • a) I haven’t had driver issues for a long time with Windows so I took it for granted that everything would just work
  • b) Installation on the virtual server went so smoothly – though on a different computer.

My server is built from old computer parts so it has actually some very old parts, now that I think about it. What was supported out of the box in Windows Server 2003 isn’t necessarily supported in the Windows Server 2008.

When troubleshooting my issues, I came across Windows Server catalog of tested products -site, where you can get some idea about supported hardware and software. Remember, many things have changed during the last 5 years and some of my components were old even then :D

Here is the hardware that caused problems for me:

  1. I had no DVD-drive on my server :D This hit me first as I hadn’t even considered it could be an issue. The server had some old SCSI CD-ROM drive but as the Windows Server 2008 comes on a DVD-image, it didn’t help much. Luckily I found some old IDE-DVD-ROM that worked fine.
  2. Windows Server 2008 didn’t recognize my Adaptec AHA-2940UW -SCSI adapter. This hit me when I got to the part in the setup where I was supposed to choose the hard disk – Setup didn’t find any :S Windows Server 2003 drivers didn’t work, but luckily Vista drivers worked. I put them on an external USB hard disk where it found them and I could continue.
  3. Finally, I have a backup mirror raid setup on Promise FastTrak TX2000 controller. It wasn’t recognized automatically, either, but after installation I got it to work through the Device Manager with Windows Server 2003 -drivers. Phew.

So, before starting the installation, take note of your hardware (especially legacy ones) and put the drivers to some easily accessible location, like some USB-disk or thumbdrive.

5. Post installation tasks

Except for the driver problems above, rest of the setup went without hitch. What happens next is the initial things to do after logging in.

First you should configure the computer name, domain/workgroup, IP-settings, virtual memory, users etc. This is easily done in the Initial Configuration Tasks -tool that collects everything together. Sweet. Changing of the computer name requires still rebooting, bummer. This was one place where the screen captures of IP-settings etc helped. I haven’t memorized my external DNS-addresses, for example.

Next you need to choose which server roles you want. This is subjective to your needs, but I decided to go with the following developer-oriented roles:

My server roles for Windows Server 2008

It is also a good idea to take captures of the settings, should you need them later, like in disaster recovery. After that you can choose which features to install.

Activating the Windows Server 2008

I like how you don’t need to enter the product key during the installation, but how it is done after the installation. It makes the installation experience much smoother and faster, as the awkward typing of the long key doesn’t cut the flow.

After the installation I tried to activate the Windows Server 2008, without first entering the product key. I was greeted with obscure “Activation Error – DNS Name does not exist” -error. If you get the same error, enter the product key first and then try activation again.

6. Installing and configuring applications

Finally, after you are satisfied with the configuration of the Windows Server 2008, it’s time to install the applications and updates.

After installing the MagicISO, I installed SQL Server 2005. Windows warns about the compatibility, but mentions that you’ll be fine if you install SQL Server 2005 SP2 afterwards.

To take advantage of all the sweetness that the .NET Framework 3.5 offers, I also installed that. You can download the full setup package from here. If you prefer the web install for some reason, it can be located from here.

IIS7 is one of the features I have waited most and after setting up the database server and accounts, it was time to configure the web server. As the GUI has changed a lot, it may take some time to get used to it, but eventually you’ll find the settings you need. IIS.net is a good place for hints.

I just made sure that I got all the most critical applications to work, but I have still some tasks left to do. Anyway, the hardest part is now behind and the fun is about to start as I can now concentrate on the new features offered by this great platform. I’m especially fascinated about the IIS7 extensibility and what it could be used for tuning the web apps, but that’s an another story.

I’d like to hear about your Windows Server 2008 experiences. Did you have any problems or do you have some tips to share?

kick it on DotNetKicks.com


Using extension methods with a data reader

February 1, 2008

Extension methods help making many routine codes much cleaner and simpler. In this post I’ll show how I use extension methods with classes that implement IDataReader such as SqlDataReader. I’ll also throw in some examples how to convert fields to enums etc tips for usual needs.

While LINQ is now the coolest kid in the block, the oldskool data readers are still the most efficient way for most cases and every now and then I still use them.

When you loop through the data reader, you have to convert each column into right type. For example:

SqlDataReader reader;

reader = sqlCommand.ExecuteReader(CommandBehavior.SingleRow);

reader.Read();

product.ProductID = Convert.ToInt32(reader["ProductID"]);

Converting data with a helper class

Typically I moved the conversion to some helper tools class to encapsulate and unify the conversion:

public static class Tools

{

public static int GetInt(IDataReader reader, string column)

{

if (reader[column] != DBNull.Value)

{

return Convert.ToInt32(reader[column]);

}

else

return 0;

}

With that helper method the code would look something like this:

product.ProductID = Tools.GetInt(reader, “ProductID”);

product.ProductName = Tools.GetString(reader, “ProductName”);

product.UnitPrice = Tools.GetDouble(reader, “UnitPrice”);

product.Discontinued = Tools.GetBool(reader, “Discontinued”);

This looks better and if I need to change the rules I can do it in one location. Still, there is a bit nicer way after the extension methods came with .NET 3.5.

Converting data with extension methods

I won’t go through the basic examples about what the extension methods are, as there already is plenty of those examples in the web. Without further ado, here are some of my extension methods for the IDataReader:

public static class DataReaderExtensions

{

public static int ToInt(this IDataReader reader, string column)

{

if (reader[column] != DBNull.Value)

{

return Convert.ToInt32(reader[column]);

}

else

return 0;

}

public static Guid ToGuid(this IDataReader reader, string column)

{

if (reader[column] != DBNull.Value)

{

return new Guid(reader[column].ToString());

}

else

return Guid.Empty;

}

public static DateTime ToDateTime(this IDataReader reader, string column)

{

if (reader[column] != DBNull.Value)

{

return Convert.ToDateTime(reader[column]);

}

else

return DateTime.MinValue;

}

//This converts an integer column to the given enum (T)

public static T ToEnum<T>(this IDataReader reader, string column)

{

if (!typeof(T).IsEnum)

{

throw new ArgumentException(typeof(T).ToString() + ” is not an Enum”);

}

return (T)Enum.ToObject(typeof(T), reader.ToInt(column));

}

I put only some examples to get the idea through, but with similar pattern you can easily add support to all the types you need.

After that I can convert the columns with less code:

//product.ProductID = Tools.GetInt(reader, “ProductID”);

//product.ProductName = Tools.GetString(reader, “ProductName”);

//product.UnitPrice = Tools.GetDouble(reader, “UnitPrice”);

//product.Discontinued = Tools.GetBool(reader, “Discontinued”);

product.ProductID = reader.ToInt(“ProductID”);

product.ProductName = reader.ToString(“ProductName”);

product.UnitPrice = reader.ToDouble(“UnitPrice”);

product.Discontinued = reader.ToBoolean(“Discontinued”);

The difference might not seem that big, but when typing that routinely line after line, you’ll notice the difference. It is also easier to read.

How about enums?

Earlier I showed the code of ToEnum<T> -extension method that converts an integer (usually primary/foreign key in a table) to an enum.

Let’s say I have Product -type and Category-enum like this:

public class Product

{

public int ProductID { get; set; }

public string ProductName { get; set; }

public double UnitPrice { get; set; }

public bool Discontinued { get; set; }

public Category Category { get; set; }

}

public enum Category

{

Beverage = 1,

Condiments = 2

}

I can convert the foreign key in the Products -table into Category -enum with the extension method, if the ID’s of the primary key match in the Categories -table:

product.Category = reader.ToEnum<Category>(“CategoryID”);

Think big – add the extension method to interface or base-type

Here is signature of one extension method:

public static int ToInt(this IDataReader reader, string column)

First comes the type you want to extend (IDataReader) and after that one extra parameter, if needed (column name in this case).

For the type parameter, I have chosen IDataReader. I used to have SqlDataReader, but then I realized that these extension methods would work with any data reader, as long as it implements the IDataReader. This made them more reusable, though I rarely use other than SqlDataReader.

Here I made sure that the extension methods work with native .NET readers that implement the IDataReader:

public static void Test()

{

int pid;

SqlDataReader sqlReader;

pid = sqlReader.ToInt(“ProductID”);

OleDbDataReader oleDBReader;

pid = oleDBReader.ToInt(“ProductID”);

OdbcDataReader odbcDataReader;

pid = odbcDataReader.ToInt(“ProductID”);

DbDataReader dbDataReader;

pid = dbDataReader.ToInt(“ProductID”);

OracleDataReader oracleReader;

pid = oracleReader.ToInt(“ProductID”);

}

Extension methods aren’t really that confusing

The blue arrows and the tooltip in the intellisense menu reveal that those are just extension methods, if you are afraid that somebody gets confused:

image

Conclusion

Extension methods help to make the .NET Framework more usable to your needs. Downside is that you’ll easily get dependent on them, but just add them to your common tools -class that you can attach to your own projects and they’ll tag along.

In projects related to work they may require some team-wide agreement, but the same applies to all the other helper classes, too.

kick it on DotNetKicks.com


Announcing articles section in blog.jemm.net

January 11, 2008

Now that I have at least some content in my articles section of my blog, I dare to spam post about new additions.

I just added a new how-to-article in the databases category:

How-To: Using SQL Server 2005’s OUTPUT to return generated identity

Previous articles are:

How-To: Common Data Patterns with LINQ to SQL
Best Practices: Database Connections

From now on I’ll mention article updates in blog posts like this. That way those of you reading this blog through the rss-feed get notified about the new articles without visiting the site.


Stored Procedures vs. Dynamic SQL – The never ending debate?

January 6, 2008

One of the recurring discussions among developers of data-driven applications is the choice between stored procedures and dynamic SQL.

Last time I stumbled upon this subject was when I started reading this post about NHibernate at Karl Seguin’s blog. Years ago one of the longest discussion was caused by this post from Frans Bouma. This is an another typical post about the subject I saw today.

I’m not going to start another rant about which is the right choice for everything, as there simply isn’t any ultimate answer. Deep Thought could argue with this, but the answer would probably take millions of years, so who cares. ;)

Use object-relational mapping for the generic stuff

My recommendation is to use dynamic SQL for the most database access methods (say, 80-90%), when coupled with a solid object-relational mapping tool or some code generation tool.

Especially with large databases that have many tables it wouldn’t be wise to code all the SQL by hand (sprocs or inline). Add tight schedules and changing requirements/database schemas and long days are guaranteed.

Usually majority of the data-access methods for normal, transactional databases are basic CRUD-operations, so why bother coding sprocs when they don’t bring any advantages?

Better choice is to use LINQ, Entity Framework or a good third-party object-relational mapper to reduce routine coding and to get lazy-loading etc.

Use stored procedures for the heavy stuff

No matter how useful OR-mappers can be, I still think that for the rest of the data access (the remaining 10-20%) stored procedures are a better option.

For complicated queries like searches and reports you often need more sophisticated SQL than what the generic tools can generate. I’m talking about queries or updates that span many tables, aggregate data or those that would require lots of round-tripping when using dynamic SQL and other client-side alternatives.

Of course you can combine all the data from automatically generated collections, but it would mean very chatty way to collect the data. With sprocs you can often get all the required information in one access to the database.

In cases like these it is better to fire up the good old Management Studio (or Query Analyzer) and optimize the queries for better results. While tuning, you can easily check the Execution Plans, index usage and logical reads (with STATISTICS IO option on).

I’m not saying that stored procedures are always automatically faster than similar dynamic SQL-clauses (they are not). My point is that manual tuning SQL by hand brings more performance as long as you know what you are doing. Crappy SQL in stored procedures (cursors, temp tables etc) won’t bring any benefits. Also, business logic belongs to the business logic layer.

When you notice that some part of the application is performing slowly, moving and optimizing that part of the code as a stored procedure could help. SQL Server Profiler is a good tool for finding slow-performing queries.

Conclusion

Like with almost everything, choosing the right tool for the right job applies here as well. Better get the best of both worlds than choosing blindly one over other.

For normal (CRUD) database operations, use object-relational mapping. However, make sure that the tool can use sprocs when needed or write helper classes for sproc-access manually as sometimes it is better to optimize the queries manually.


SQL Server Best Practices -links

November 26, 2007

If you want some good guidance for SQL Server tuning, check out this collection of links:

"Get the real-world guidelines, expert tips, and rock-solid guidance to take your SQL Server implementation to the next level. These SQL Server best practices draw on the extensive experience and expertise from respected developers and engineers at Microsoft, who walk you through the specifics on solving particularly difficult issues."

http://technet.microsoft.com/en-us/sqlserver/bb331794.aspx

Technical White Papers

  • Precision Considerations for Analysis Services Users
  • Identifying and Resolving MDX Query Performance Bottlenecks in SQL Server 2005 Analysis Services
  • XML Best Practices for Microsoft SQL Server 2005
  • Performance Optimizations for the XML Data Type in SQL Server 2005
  • SQL Server 2005 Security Best Practices – Operational and Administrative Tasks
  • SQL Server 2005 Full-Text Queries on Large Catalogs: Lessons Learned
  • Scale-Out Querying with Analysis Services
  • SQL Server 2005 Analysis Services Processing Best Practices
  • Predeployment I/O Best Practices
  • Partial Database Availability
  • Comparing Tables Organized with Clustered Indexes versus Heaps
  • SQL Server 2005 Deployment Guidance for Web Hosting Environments
  • Resolving Common Connectivity Issues in SQL Server 2005 Analysis Services Connectivity Scenarios
  • Implementing Application Failover with Database Mirroring
  • OLAP Design Best Practices for Analysis Services 2005
  • DBCC SHOWCONTIG Improvements and Comparison between SQL Server 2000 and SQL Server 2005
  • TEMPDB Capacity Planning and Concurrency Considerations for Index Create and Rebuild
  • Loading Bulk Data into a Partitioned Table
  • Database Mirroring Best Practices and Performance Considerations
  • SQL Server 2005 Performance Tuning using Waits and Queues
  • Analysis Services 2005 Performance Guide
  • SAP with Microsoft SQL Server 2005: Best Practices for High Availability, Performance, and Scalability
  • Troubleshooting Performance Problems in SQL Server 2005
  • More links at the TechNet -site. Check it out! :)


    Entity Framework Beta 2 & Tools CTP1 released!

    August 28, 2007

    While browsing through feeds, I spotted these news - Entity Framework Beta 2 is now available for download.

    I believe that once Entity Framework is ready, it’ll work sweetly with the LINQ to Entities. That way you’ll get best of both worlds. The figure on the right (copied from the MSDN) describes the architecture and relations of the Entity Framework, LINQ and ADO.NET well.

    image

    The new features and improvements in the Entity Framework include:

    • Events to customize code generation
    • Abstract types in EDM models
    • Complex types
    • <Using> support in metadata files
    • Entity key serialization
    • Increased persistence ignorance in entity data classes
    • Improved connection management in ObjectContext
    • Improved DataBinding usability
    • Metadata annotations
    • Better support for span over LINQ to Entities queries
    • Improvements to LINQ queries: additional canonical functions and automatic mapping from CLR functions to server functions
    • A new event for extensibility of SaveChanges
    • Usability and consistency improvements
    • Polymorphic results from stored procedures

    If you are interested in trying out this beta, be sure to test the tools (CTP1), too. The tools will bring you the joys of Entity Designer, Entity Mapper, Entity Model Browser and Visual Studio Integration.

    Other useful links:

    I’ve been bit busy lately due to moving to new apartment this week and otherwise busy, so there haven’t been lately as much time for blogging as I have hoped. It’ll be fixed soon, though :)


    Understanding SQL Server 2005 editions

    August 20, 2007

    The amount of SQL Server 2005 editions can be confusing and sometimes it can be hard to choose the right edition. This is especially true with the smaller editions, like the Express Edition and Compact Edition that on the surface look the same.
    The editions currently listed on the SQL Server 2005 homepage are:

    Mini-FAQ

    Q: What is the difference between Developer Edition and another editions?

    A: Developer Edition has all the same features as the Enterprise Edition. Unlike Enterprise Edition, it shouldn’t be used for other purposes than development. In addition to Windows Server, Developer Edition can be installed on a workstation OS like Windows XP and Vista. Enterprise and Standard Edition require Windows Server.

    Q: What about the Express Edition? Couldn’t I just use it instead of the Developer Edition?

    A: Express Edition is easier to obtain, but it doesn’t have all the same features that the Developer / Standard / Enterprise have. For example, if you need to develop for Reporting Services or Service Broker, then the Express-version isn’t enough.

    Express Edition is the edition that replaced the MSDE.

    Q: What’s the difference between Express Edition and Compact Edition?

    A: SQL Server Express Edition is aimed primarily as a service-oriented database and Compact Edition is better suited for local storage. For example, with ASP.NET application you would choose the Express Edition, but for a WinForm/WPF application you would choose the Compact Edition.

    The Compact Edition is actually just a bunch of DLL’s that run in-process with your application. It doesn’t require separate installer and the size is very small, under 2MB!

    Express Edition installer is about 57MB and it takes 197MB disk space after installation. Compact Edition also runs on Windows Mobile devices (like SQL Server CE did).

    There are trade-off’s in the Compact Edition, of course. Here are the most important ones:

    • Not all the T-SQL -features work (if, case etc)
    • There is no support for sprocs, views or native XML/XQuery
    • The number of connections is limited to 256 (unlimited in Expression), but it is for local storage, anyway.
    • No role-based security

    Here is an excellent white paper on the Microsoft’s SQL Server -site. The whitepaper not only describes well the differences between the Express and Compact Edition, but it also compares the goals of all editions briefly. Worth reading out, if you want to make sure you know everything about SQL Server editions. It has also good security tips.

     Q: What is the SQL Server Everywhere Edition?

    A: It was just another name of the Compact Edition before the name was changed.

     Q: What is the SQL Server Embedded Edition?

    A: It is hard to find much information about it. A post by Microsoft employee says: “This is an embedded data service that can only be used by a handful of Windows Services.”

    People seem to learn about it when installing the Windows SharePoint Services in single server / stand-alone mode, which installs the SSEE on their machines. Then they realize the mistake as they wanted to use an existing instance of SQL Server (to save resources). The next step is to try to remove the Embedded Edition, but it isn’t in the Control Panel!

    Luckily, there is a way to uninstall the SQL Server Embedded Edition.

    Yes, I’ve been there, too. Apparently I’m not the only one, as that is my most popular blog post so far with several daily views. Rumors tell that it will be called SQL Server PITA Edition in the next version :D

    Remember kids: When installing Window SharePoint Service (WSS) and you want to control your data better, always choose the advanced setup and web farm -mode to save yourself some trouble.

    Commit … er… conclusion

    I wanted to make things clearer to myself and hopefully some other reader will find some joy out of this post.  I’m definitely going to do tests with the Compact Edition some day and I promise I’ll post here some results when I get more experience and some tips to share.


    Common Data Patterns with LINQ

    August 9, 2007

    How to uninstall SQL Server 2005 Embedded Edition

    August 6, 2007

    Note: This is a repost from an another blog of mine that was located at the SharePoint Blogs. It recently had a huge hardware failure and many blogs got lost. Since I didn’t have much posts there, I’ll just repost this most popular/useful entry here for future reference.

    I tried to install WSS v3 and for some reason I didn’t choose the Advanced / Web Fronted-setup in the beginning so the installer installed the SQL Server 2005 Embedded Edition. I wanted to use an existing instance of SQL Server 2005 so I had to uninstall the WSS v3 and the SQL Server EE before reinstalling.

    The problem is that you can’t uninstall the SQL Server 2005 EE from the Control Panel, but it is a hidden instance. Fortunately there is a solution, which I found with a simple search (source link is dead, so I removed it):

    To uninstall SSEE:
    Start Registry Editor, and then locate the following registry key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall

    In the left pane, click each GUID.
    For each GUID that you click, look for a display name in the right pane that matches “Microsoft SQL 2005 Embedded Edition…”.

    When you see a display name that matches the name, copy the value of the Key named “UninstallString”
    Open a Command-Window (Start->run->cmd)
    Paste the Copied string.
    Append “CALLERID=OCSETUP.EXE” eg “MsiExec.exe /X{BDD79957-5801-4A2D-B09E-852E7FA64D01} CALLERID=OCSETUP.EXE”

    There you go
    Don’t forget to reboot.
    Hope that helps
    Patrick

    Yes, it helped. Thanks, Patrick :)