A couple of developers believe strongly that values for every dropdown list should come from the database, even if it's something like gender and marital status. I mean this is stuff that never changes - I wouldn't wake up to read the newspaper headline on a new gender being introduced unless I lived in mutant city at Chernobyl or Hiroshima.
In a traditional C program, you can use constants to keep track of the values for globally static data. For an ASP.NET application, it makes perfectly good sense to declaratively set the values in the dropdown lists. If you must keep the values as (numeric) IDs, you might as well use an enumeration. To support a null, you can either use nullable types (.NET 2.0 feature) or add a NotSpecified as the first enumeration value. If you have absolutely got to store values in the database, you could create a stored procedure that returns values from a temporary table or put together the values in a single dataset using SELECT and UNION. There's no use adding extra disk I/O or taking up cache space for something you know will absolutely never change!
Sunday, November 16, 2008
Windows 2008 R2 to release in 2010
Microsoft plans to release Windows 2008 Release 2 in the year 2010. New features include HyperV 2.0 and Powershell 2.0. You can get more details about the release here
Saturday, November 15, 2008
ScreenCast: Schema Binding in MS SQL Server
Schema Binding in SQL Server from Nitin Reddy on Vimeo.
This is my 2nd attempt at creating a screencast for my blog. I made a couple of grammatical errors on the subtitles and the laptop's fan sound is annoying. I'll have those issues ironed out in my next screencast though so keep watching this blog for more coming your way.
Friday, November 14, 2008
More Efficient and Accurate Date-Time Data Types in MS SQL 2008
MS SQL Server 208 includes several new data types, one of which the the 'date' data type which occupies 4 bytes. Most applications that need to store only the date currently use the datetime data type which uses up 8 bytes.
Also available is the 'datetime2' data type which can store date & time with much more accuracy than the 'datetime' data type.
The date and time data types included with SQL Server 2008 are:
time, date, smalldatetime, datetime, datetime2, datetimeoffset
Also available is the 'datetime2' data type which can store date & time with much more accuracy than the 'datetime' data type.
The date and time data types included with SQL Server 2008 are:
time, date, smalldatetime, datetime, datetime2, datetimeoffset
Wednesday, November 12, 2008
Remoting with .NET
Remoting simplies development of client-server or service-oriented applications greatly. To start off, you need an interface that declares all the methods that you would like to make available to the client application. This interface should ideally be placed in a client library that you can reference from both the server and the client application, but you can also define the interface in both applications.
Example: Interface (Server & Client)
We now need to define the class implements this interface.
Example. Service class (Server)
Next, we need to make a hosting application that can serve the requests of the client application. The end point for the service class needs to be defined. The server application should ideally be a Windows Service application, but can also be a console or windows forms application.
Example. Server application (Server)
The client application doesn't really have all that much to do - it needs to get an instance of the service object and make method calls.
Example. Client application (Client)
Example: Interface (Server & Client)
namespace Sinkhole1
{
public interface IWiseMonk
{
int getSquare(int a);
}
}
We now need to define the class implements this interface.
Example. Service class (Server)
namespace Sinkhole1
{
[Serializable]
public class WiseMonk : MarshalByRefObject, IWiseMonk
{
public int getSquare(int a)
{
return a * a;
}
}
}
Next, we need to make a hosting application that can serve the requests of the client application. The end point for the service class needs to be defined. The server application should ideally be a Windows Service application, but can also be a console or windows forms application.
Example. Server application (Server)
namespace Sinkhole1
{
class Program
{
static void Main(string[] args)
{
RemotingConfiguration.ApplicationName = "WiseMonk";
WellKnownServiceTypeEntry wkste = new WellKnownServiceTypeEntry(typeof(WiseMonk), "MathEngine", WellKnownObjectMode.SingleCall);
RemotingConfiguration.RegisterWellKnownServiceType(wkste);
TcpChannel tch = new TcpChannel(109);
ChannelServices.RegisterChannel(tch, false);
//Keep the server waiting for client requests
Console.ReadLine();
}
}
}
The client application doesn't really have all that much to do - it needs to get an instance of the service object and make method calls.
Example. Client application (Client)
namespace SinkHole1Client
{
class Program
{
static void Main(string[] args)
{
IWiseMonk iwm = (IWiseMonk) Activator.GetObject(typeof(IWiseMonk), "tcp://localhost:109/WiseMonk/MathEngine");
Console.Write(iwm.getSquare(5));
Console.ReadLine();
}
}
}
Tuesday, November 11, 2008
Ubuntu 8.10 guest user
You've probably heard about the release on Ubuntu 8.10 (Intrepid Ibex) on 30th last month. Apart from a newer kernel and updated packages, the new release supports guest sessions that prevent users from writing to disk. I'll post more about it as soon as I get myself a copy of the DVD edition.
Sunday, November 9, 2008
MS SQL Views Don't Sort Data
If you're new to Microsoft SQL Server, one of the things that would bite you in the back is the ORDER BY clause within a view. SQL Server displays an error when you try to include an ORDER BY clause within the SQL statement used to define the view, but you can get around the warning by using the TOP 100 PERCENT clause. This, however, does not force SQL Server (2008) to order the data - the ORDER BY clause is simply used to determine which rows will be returned in the dataset.
It's probably Microsoft's way to put an end to developers' abuse of the sort functionality - sort the data once from a view, again in a subquery and finally in the select statement returning the final data.
It's probably Microsoft's way to put an end to developers' abuse of the sort functionality - sort the data once from a view, again in a subquery and finally in the select statement returning the final data.
Natural Joins - Still not in MS SQL Server
One of the coolest join options in Oracle is the Natural Join. Provided that the tables' columns were named such that the column name indicated which columns in two or more tables should be used for a join, it reduced the effort in writing SQL queries.
Instead of writing a:
SELECT ContactName, CityName
FROM Contact
JOIN City ON Contact.CityId = City.CityId
you could simply write:
SELECT ContactName, CityName
FROM Contact
NATURAL JOIN City
Considering how Microsoft has been trying to make development easier for software programmers, this is one feature that they ought to think about.
Instead of writing a:
SELECT ContactName, CityName
FROM Contact
JOIN City ON Contact.CityId = City.CityId
you could simply write:
SELECT ContactName, CityName
FROM Contact
NATURAL JOIN City
Considering how Microsoft has been trying to make development easier for software programmers, this is one feature that they ought to think about.
Subscribe to:
Posts (Atom)