Thursday, June 14, 2012

How to insert records on SQL Server identity column?

Scenario:


Insert records in SQL Server table with pre-defined primary key on an identity column. For instance, the the data ContactId to insert is from 11-50. How to insert the ContactId as my identity column value is 150 now? The assumption here is existing ContactId  in the range could be deleted for the new INSERT.

 Concepts:

Identity column on a table increment the value automatically for each record INSERT into the table. For example, the table "Contact" has an identity column defined on ContactID column. The column is defined to increase the max identity value by 1. This is done by specifying the increment value to 1.

The seed value lets you specify the identity column starting value. For instance, I would like to start all data from ContactId = 100.


The T-SQL table create statement looks like below:


Solution:


Turn the IDENTITY_INSERT ON to tell the server that you want to insert specific ID value. Perform the record insert. Enable the identity columns auto value by setting the IDENTITY_INSERT OFF.

Syntax:
SET IDENTITY_INSERT [ database. [ owner. ] ] { table } { ON | OFF }

Example:




Further references:


MSDN Table Identity Column
MSDN IDENTITY_INSERT

Thursday, June 07, 2012

How to configure Windows 7 Remote Desktop to use different port number

Scenario

Imagine you would like to disable the remote desktop session for all users but not yourself.  You can definitely restrict remote desktop users using the Local Security Policy. Then, what if the domain users is part of Administrator group who can remote desktop and you do not wish to change that? 

One way to achieve that is to change the RDP default port 3389. For example use port 3391 for RDP.

How to configure specific port number


   Figure 1.0 RDP port number registry key
  1. Edit the RDP port number (in windows registry) from 3389 to 3391. Run regedit tool and navigate the registry key [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp]
  2. Double click on the registry value, select Decimal and type in 3391.
  3. Logoff the session
  4. Remote Desktop and specify the computer with port number. If your computer name is LUCKY, then specify it to Lucky:3391 and click connect (as shown below).
  5. Voila.
 









Figure 2.0 RDP connect with port number

Possible Issue1 - Unable to RDP using Lucky:3391

Details 

Error might goes like "Remote Desktop Can't Connect to the remote computer for one of these reason ....".

Possible cause

The computer that is used to remote desktop is blocking port 3391. Windows Firewall is blocking port 3391.

Diagnose: How to check the port is blocked by Windows Firewall

  1. Check Window Firewall is ON. If not, check for any 3rd party firewall.
  2. Check whether port 3391 is blocked by running telnet command from command prompt.
  3. Command text => telnet LUCKY 3391 (Assume Computer name = LUCKY and port = 3391)
  4.  If the port is blocked, you should see the screen below







Figure 3.0 Diagnose with Telnet

Solution: Add firewall port number exception (for Windows Firewall)

Steps

  1. Add the port 3391 to your firewall exception rule. This will allow your computer to connect to port 3391.
  2. Open Windows Firewall settings. This could be done by typing firewall.cpl into the command line. Click on Advance Settings.
  3. Create an Outbound Rule on TCP port 3391. Name the rule and close the window
    
Figure 4.0 Firewall Exception

Further reference

Friday, May 25, 2012

Buy Wireless USB Adapter for Windows 7

Scenario

My Netgear 54Mbps 802.11b/g usb wifi dongle has joined the broken list recently. I am aware that  Wireless PCI network card is a clear winner for desktop computer (compare to usb dongle). It uses less processor cycle and faster.

However, I opted for the Usb dongle instead. The reason is I have 2 desktop computers. I can swap it to another computer. Imagine unplugging the wireless PCI adapter card..... 

How do you know which Usb dongle works with Windows 7? Does it support 32 bits or 64?

Find out the answer from Microsoft official Windows 7 Certified Usb Wireless adapter Compatibility page.



The logo indicates:

"We focused on robust testing requirements to ensure optimal Windows 7 experience. Products that receive the Logo are checked for common issues to minimize the number of crashes, hangs, and reboots experienced by the user."

I end up buying the following from Amazon. Apparently many good reviews.

Edimax EW-7811Un Network adapter



What to consider when buying a new wireless USB adpater?


1. Security/Encryption
Avoid WEP as it's less secure wireless protocol (exists in the older version of wifi adapter). Look for WPA, WPA2/AES.

2. Network compatability (802.11a/b/g/n)
Does the dongle need to be backward compatible with specific 802.11b router? Or do you intend to use the dongle to connect to other 802.11x router? If you only have one 802.11n router, just get the dongle that support 802.11n.

3. Draft version
Watch out for 802.11n or  draft 802.11n. Avoid draft version by checking manufacture specification.

4. USB compatibility. USB1.0, 1.1, 2.0 or 3.0. 
Which version does your desktop computer supports?

5. Software set up. 
Does the dongle software allows you to save configuration profile?

6. Range. 
New usb dongle has MIMO technology that increase range, realiability and speed. Dearer indeed.

7. Issues. Check online forum whether it has overheating or battery draining issue (if use on old laptop).

I hope you find this post useful. :)