Friday, August 03, 2007

Making a normal Column, an Identity column in SQL Server

Do you know that you cannot just change a normal column into an identity column in SQL Server? This is because that identity columns can only be created when creating new tables.

Now some people will say that how cannot that be? Because they are used to change using the SQL Server Management Studio (SQLSMS). What management studio will do is, it will create a temporary table with the Identity column and copy all your existing data there. Later it will delete the original table and will rename the temporary table to the original.

For example we will take Sales.Individual table in the AdventureWorks database.



Think that we need to add a column named Id as an identity column. What we will do is just type after ModifiedDate column and make the new column an identity column.

In such a case when we save the change SQLSMS will first create a temporary table which matches the new schema with the identity column.

Then it will set IDENTITY INSERT OFF and will copy the data from the original table to the newly created temporary table.

After this it will delete the original table and will rename the temporary table as the original table.

Did any one thought that the SQLSMS is doing this much of work for us without our knowledge?
Retrieving Schema Information of SQL CE Database

There are very limited features offered in SQL Compact Edition (SQL CE). But with those offered you can do many things if you know what is there and what is not there.

Following are some views available in SQL CE which you can use to retrieve information about the tables in the database.

-- Gets the list of Columns with their associated Tables. You will be able to retrieve the column properties such as Data Type, Allow Null, Default Values, etc.
SELECT * FROM INFORMATION_SCHEMA.COLUMNS

-- Retrieves information about the indexes contained in the database.
SELECT * FROM INFORMATION_SCHEMA.INDEXES

-- Retrieves information about the Primary Keys used in the tables.
SELECT * FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE

-- Retrieves all the Tables in the database including the System tables.
SELECT * FROM INFORMATION_SCHEMA.TABLES

-- Retrieves all the Constrains in the database.
SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS

-- Retrieves all the Data Types available in the database.
SELECT * FROM INFORMATION_SCHEMA.PROVIDER_TYPES

-- If you have any referential integrity constraints in your database defined, those will be returned by this.
SELECT * FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS
Did you ever thought why we are saying "Many Happy Returns of the Day" on someones Birthday

Visit this link and find out more.
http://www.smh.com.au/news/big-questions/why-do-you-wish-a-person-many-happy-returns-of-the-day-on-theirbirthday/2005/08/25/1124562965035.html

Thursday, August 02, 2007

Dual Booting Windows Vista

As I normally need several Operating Systems installed in my machine, after installing Vista also I tried the same. This made me to find, that the Vista boot loader is different to the earlier OS boot loaders. Because of this difference if you install earlier version of OS after installing Vista, you will not be able to start Vista.
These are the things which I found out.
If you need to multi boot Vista, then first install the oldest OS first. If the OSes are Windows XP, Windows 2003 and Windows Vista then install Windows XP first then Windows 2003 and finally Windows Vista.
Also note that if you install any earlier version after installing Vista you will have to fix the Vista boot loader. This can be done by booting the computer using the Vista installation CD and trying a start up recovery.
A good article is located at http://www.itnews.com.au/News/NewsStory.aspx?story=55148.
Retrieving MAC Address in Compact Framework

Recently I have seen that getting the MAC address of a Pocket PC network card using the .Net Compact Framework requires calling to the API 'iphlpapi.dll'. This is because the Windows Management Instrumentation (WMI) classes are not in Compact Framework. Otherwise you should have used WMI to get the MAC address.
But believe me that the process involved in Compact Framework to get the MAC address is complex. So as a suggestion I would say to use the OpenNETCF class libraries. You have to use OpenNETCF.Net and OpenNETCF to successfully get the MAC address. If you want to know what is happening underneath you also can download the OpenNETCF source code too.

OpenNETCF web site is http://www.opennetcf.com/, visit them and see.

The code for getting the MAC address of the first adapter using OpenNETCF would be,

' Creating a variable to hold all the retrieved adapters.
Dim adpcol As OpenNETCF.Net.AdapterCollection = OpenNETCF.Net.Networking.GetAdapters
If adpcol.Count = 1 Then
' adpcol.Item(0).MacAddress will be returning in Byte stream, you have to use Bit Converter to convert the stream to string.
GetDeviceMAC = BitConverter.ToString(adpcol.Item(0).MacAddress)
Else
GetDeviceMAC = "No Adapters Fetched"
End If

(You have to refer OpenNETCF.Net and OpenNETCF to make this code run.)
Yahoo! Go 2.0


Have you tried Yahoo Go 2.0? It has many new additions than the earlier version of Yahoo Go. In supported areas you can even get the traffic reports and maps.

Also note that Yahoo Go 1 service will be stopped on 27th of August 2007.

Try it out at http://mobile.yahoo.com/go.

I am sure that you will like the new version with many new features.

Thursday, July 12, 2007

Analyzing Device Application Performance


Recently I tried analyzing my applications' performance running on a Pocket PC. This can be achieved using .Net Compact Framework (.Net CF) Remote Performance Monitor (RPM). .Net CF RPM provides facility to monitor applications which run on devices that are connected to the computer using Active Sync or by general network.

To monitor your device application performance you have to have at least .Net CF SP1 since .Net CF RPM will come with .Net CF Service Pack 1. If you have not yet installed .Net CF SPs then download the SP2 from Microsoft using the following link.
http://www.microsoft.com/downloads/details.aspx?FamilyID=aea55f2f-07b5-4a8c-8a44-b4e1b196d5c0&DisplayLang=en


RPM consists of 3 main files.
1. NetCFRPM.exe - This is the application file which will run on your computer. This will show performance related data of the device application. This file can be found at C:\Program Files\Microsoft.NET\SDK\CompactFramework\v2.0\bin if you installed the Service Packs to the default location.

2. netcflaunch.exe - This will give you the connection parameters to the device. The details provided will be in handy if the device is not connected to the computer using Active Sync.

3. netcfrtl.dll - This dll facilitates the connection between the computer and the device.

You have to copy both above files to the device Windows folder (\Windows).


If you need more information on how to use .Net CF RPM visit Steven Pratschner's .Net CF weblog articles.
http://blogs.msdn.com/stevenpr/archive/2006/04/17/577636.aspx
http://blogs.msdn.com/stevenpr/archive/2007/03/08/finding-managed-memory-leaks-using-the-net-cf-remote-performance-monitor.aspx