Sunday, July 17, 2011

Disable/Enable Windows default debugger Dr. Watson

If you feel it's useless for you anyway, just follow these steps to turn off.

1.Go to Start Menu -->> Run and type regedit.exe then press Enter.

2.Browse to the following registry. HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\AeDebug

3.Click the AeDebug key, and then click Export Registry File on the Registry menu. Save the file and remember it.

4.Then you can delete the AeDebug key.
 
That's it! Whenever any programs crash again, Windows won't ask you whether you want to send data to Microsoft or not.

If you change your mind and want to enable Dr. Watson back. It's easy.
* Double-click the file you save in step 3.
* And then go to Start -->> Run -->> cmd.exe
* At the command prompt, type drwtsn32 -i

Tuesday, May 24, 2011

How to Disable / Remove Annoying Shutdown Event Tracker (Shutdown Reason UI) in Windows Server 2003 / 2008?

If you are using Windows Server 2003 or 2008, you might have noticed that whenever you click on Shutdown button, it shows a dialog box asking you the reason behind shutting down the system. You have to select an option from drop-down box or write into Comment box to be able to shutdown the system.


Many people find it very annoying and want to disable it but they don't know how to disable it.

Today in this tutorial, we'll tell you a simple way to completely remove this annoying dialog box:

METHOD 1: Using Group Policy Editor

1. Type gpedit.msc in RUN dialog box and press Enter.

2. It'll open Group Policy Editor. Now go to:

Computer Configuration -> Administrative Templates -> System

3. In right-side pane, look for "Display Shutdown Event Tracker" option.


4. Now double-click on "Display Shutdown Event Tracker" and select "Disabled". Apply it and the annoying dialog box will never appear again.

NOTE: You can also use this method to enable Shutdown Event Tracker in Windows client OS like Windows XP, Vista, 7, etc. Just set the option value to "Enabled".

METHOD 2: Using Registry Editor

If you face problems while using Group Policy Editor, you can also use Registry Editor to do the same task.

1. Type regedit in RUN dialog box and press Enter.

2. It'll open Registry Editor. Now go to:

HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows NT

3. Under "Windows NT" key, look for a key "Reliability". If its not present, create it.

4. Now select "Reliability" key and in right-side pane, look for following 2 DWORD values:

ShutdownReasonOn
ShutdownReasonUI

If the DWORD values are not present, create them.

5. Now set values of both DWORD to 0


6. That's it. Now you'll not see the reason dialog box while shutting down the system.



NOTE: You can also use this method to enable Shutdown Event Tracker in Windows client OS like Windows XP, Vista, 7, etc. Just set the values of both DWORD to 1 using Step 5.

Monday, May 16, 2011

Enter key is not working in Firefox Resolved

This problem is due to AVG Safe Search Extension for Firefox.

Step:1 Go to Firefox’s
Step:2 Tools–>Add-Ons–>Select Extensions then disable AVG Safe Search extension.

After this restart your firefox browser.

Saturday, May 14, 2011

Just In Time(JIT) Debugger Error Resolved


I found this actually resolved my issue with JIT:


1. Click Start


2. Click Run


3. Type cmd (and click ok)


4. Type drwtsn32 -i (and press enter)

Wednesday, May 11, 2011

Configure XAMPP Apache and IIS to Run Together on Windows XP or Windows Vista

The task is now simplified by 2 steps below

1. Change Apache port
Open C:\xampp\apache\conf\httpd.conf
Replace “Listen 80″ with “Listen 81″
Replace “ServerName localhost:80″ with “ServerName localhost:81″

2. Change SSL port
Open C:\xampp\apache\conf\extra\httpd-ssl.conf
Replace “Listen 443″ with “Listen 4430″
Replace “VirtualHost _default_:443” with “VirtualHost _default_:4430”
Replace “ServerName localhost:443″ with “ServerName localhost:4430″


That's all. Easy isn't it?

Tuesday, May 10, 2011

Fill Drop Down List Box using data table.

Using C#

string qry = "Select * from table";
con.Open();
DataTable dt = new DataTable();
dt.Columns.Add("field1");
dt.Columns.Add("field2");
SqlCommand cmd = new SqlCommand(qry, con);
SqlDataReader dr = cmd.ExecuteReader();
if ((dr.HasRows))
{
    while (dr.Read)
    {       
        DataRow drr = null;
        drr = dt.NewRow();
        drr["field1"] = dr("field1").ToString;
        drr["field2"] = dr("field2").ToString;
        dt.Rows.Add(drr);       
    }
}
con.Close();
ddl_Temp.DataSource = dt;
ddl_Temp.DataValueField = "field1";
ddl_Temp.DataTextField = "field2";
ddl_Temp.DataBind();


Using VB. Net

Dim qry As String = "Select * from table"
con.Open()
Dim dt As New DataTable()
dt.Columns.Add("field1")
dt.Columns.Add("field2")
Dim cmd As New SqlCommand(qry, con)
Dim dr As SqlDataReader = cmd.ExecuteReader()
If (dr.HasRows) Then
 While dr.Read
  Dim drr As DataRow = Nothing
  drr = dt.NewRow()
  drr("field1") = dr("field1").ToString
  drr("field2") = dr("field2").ToString
  dt.Rows.Add(drr)
 End While
End If
con.Close()
ddl_Temp.DataSource = dt
ddl_Temp.DataValueField = "field1"
ddl_Temp.DataTextField = "field2"
ddl_Temp.DataBind()

Monday, May 9, 2011

Query to find nth max value of a column

Consider the following Employee table with a single column for salary.
                          +------+
                          | Sal  |
                          +------+
                          | 3500 | 
                          | 2500 | 
                          | 2500 | 
                          | 5500 |
                          | 7500 |
                          +------+
The following query will return the Nth Maximum element.
select SAL from EMPLOYEE E1 where 
 (N - 1) = (select count(distinct(SAL)) 
            from EMPLOYEE E2 
            where E2.SAL > E1.SAL )
For eg. when the second maximum value is required,
  select SAL from EMPLOYEE E1 where 
     (2 - 1) = (select count(distinct(SAL)) 
                from EMPLOYEE E2 
                where E2.SAL > E1.SAL )
 
                    +------+
                    | Sal  |
                    +------+
                    | 5500 |
                    +------+
 
The following query will return the Nth Minimum element.
select SAL from EMPLOYEE E1 where
 
(N - 1) = (select count(distinct(SAL))
           
from EMPLOYEE E2
           
where E2.SAL < E1.SAL )
For eg. when the second Minimum value is required,
  select SAL from EMPLOYEE E1 where
     
(2 - 1) = (select count(distinct(SAL))
               
from EMPLOYEE E2
               
where E2.SAL < E1.SAL )

 
                    +------+
                    | Sal  |
                    +------+
                    | 3500 |
                    +------+
 
 
Second Way:---


DECLARE @SalaryPosition INT
SET @SalaryPosition = 2
SELECT *
FROM Employee E1
WHERE @SalaryPosition =  
          (
            SELECT COUNT(DISTINCT E2.Salary) 
            FROM Employee E2
            WHERE E2.Salary >= E1.Salary
          ) 
 
 
SELECT TOP 1 salary

FROM (

SELECT DISTINCT TOP 6 salary

FROM employee

ORDER BY salary DESC) a

ORDER BY salary

You can change and use it for getting  nth highest salary from Employee table as follows

SELECT TOP 1 salary

FROM (

SELECT DISTINCT TOP n salary

FROM employee

ORDER BY salary DESC) a

ORDER BY salary

where n > 1 (n  is always greater than one) 

Thursday, May 5, 2011

Fixing the localhost authentication problem in FireFox

For some time I had a strange problem; I could load sites from http://localhost in MSIE, but whenever I tried FireFox, it asked me for an user name and password. I've tried it all but I couldn't authenticate.
If you happen to have the same problem, here's a quick and simple workaround:

  1. In Firefox type about:config in the addressbar
  2. It will show you a warning message ignore it and click on the button.
  3. Find the preference named network.automatic-ntlm-auth.trusted-uris
  4. Doubleclick and type localhost
  5. Enter and you're done

Wednesday, May 4, 2011

How to Remove Startup Entries from MSConfig

Do you have obsolete startup entries that flood your MSConfig list? Did you know you can remove them through your registry? Here is how, 9 steps to remove unused entries…
MSConfig
Note: This is for Windows XP only.
  1. Open your msconfig (you type “msconfig” in your Run from your start menu)
  2. Switch to “Startup or services tab”
  3. Uncheck the services or startup programs to stop it from running on windows startup
  4. Open your registry editor (you type “regedit” in your Run from your start menu)
  5. Select “My Computer”under the list in Registry Editor
  6. Select Edit > Find (or Ctrl+F)
    MSConfig2
  7. Check on “Keys” while unchecking everything else, and hit Enter to search for “msconfig
    MSConfig3
  8. When done searching, it will bring you to this directory in the Registry Editor (HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\MSConfig)
    MSConfig4

    Note: Only unchecked entries will appear in startupfolder/startupreg/services.
  9. Delete those folders under startupfolder/startupreg, or services.
  10. You are done!
    MSConfig5

    Note: Unchecked entries were deleted.

Wednesday, April 27, 2011

Add/Substract Min/sec with DateTime in c#

To Add Minutes/Seconds

<datetime variable>.AddMinute(double value);
<datetime variable>.Addseconds(double value);


To Substract Minutes/Seconds

<datetime variable>.AddMinute(-(double value));
<datetime variable>.Addseconds(-(double value));

Friday, April 22, 2011

how can we know the OS the client is using

Using C# Code Behind

You can use the following code to find out if the incoming request is from any Mobile device or not (the following code is not updated for Android but you can easily build on it).

string strUserAgent = Request.UserAgent.ToString().ToLower();
if (strUserAgent != null)
{
        if (Request.Browser.IsMobileDevice == true || strUserAgent.Contains("iphone") ||
             strUserAgent.Contains("blackberry") || strUserAgent.Contains("mobile") ||
             strUserAgent.Contains("windows ce") || strUserAgent.Contains("opera mini") ||
             strUserAgent.Contains("palm"))
        {
                //Request from Mobile Device
        }
        else{
                //Request from Computer
        }
}
Once, request is identified to be orignated from any computer, you can put the following code to detect its operating system.

if (Request.UserAgent.IndexOf("Windows NT 5.1") > 0)
{    //Windows XP 
}
else if (Request.UserAgent.IndexOf("Windows NT 5.0") > 0)
{    //Windows 2000
}
else
{    //Other Operation System 
}
 

Using .aspx Page     



Paste this in an .aspx page no code behind needed.
    <!-- p class="title">Browser Capabilities :</p -->
        
        <table width="90%" border="0" align="center" 
                cellpadding="2" cellspacing="2">
                <tr class="header">
                        <td width="30%">Property</td>
                        <td>Value</td>
                </tr>
                <tr>
                        <td>ActiveXControls </td>
                        <td> <%= Request.Browser.ActiveXControls %></td>
                </tr>
                <tr>
                        <td>AOL </td>
                        <td> <%= Request.Browser.AOL %></td>
                </tr>
                <tr>
                        <td>BackgroundSounds </td>
                        <td> <%= Request.Browser.BackgroundSounds %></td>
                </tr>
                <tr>
                        <td>Beta </td>
                        <td> <%= Request.Browser.Beta %></td>
                </tr>
                <tr>
                        <td>Browser </td>
                        <td> <%= Request.Browser.Browser %></td>
                </tr>
                <tr>
                        <td>CDF </td>
                        <td> <%= Request.Browser.CDF %></td>
                </tr>
                <tr>
                        <td>ClrVersion </td>
                        <td> <%= Request.Browser.ClrVersion %></td>
                </tr>
                <tr>
                        <td>Cookies </td>
                        <td> <%= Request.Browser.Cookies %></td>
                </tr>
                <tr>
                        <td>Crawler </td>
                        <td> <%= Request.Browser.Crawler %></td>
                </tr>
                <tr>
                        <td>EcmaScriptVersion </td>
                        <td> <%= Request.Browser.EcmaScriptVersion %></td>
                </tr>
                <tr>
                        <td>Frames </td>
                        <td> <%= Request.Browser.Frames %></td>
                </tr>
                <tr>
                        <td>JavaApplets </td>
                        <td> <%= Request.Browser.JavaApplets %></td>
                </tr>
                <tr>
                        <td>JavaScript </td>
                        <td> <%= Request.Browser.JavaScript %></td>
                </tr>
                <tr>
                        <td>MajorVersion </td>
                        <td> <%= Request.Browser.MajorVersion %></td>
                </tr>
                <tr>
                        <td>MinorVersion </td>
                        <td> <%= Request.Browser.MinorVersion %></td>
                </tr>
                <tr>
                        <td>MSDomVersion </td>
                        <td> <%= Request.Browser.MSDomVersion %></td>
                </tr>
                <tr>
                        <td>Platform </td>
                        <td> <%= Request.Browser.Platform %></td>
                </tr>
                <tr>
                        <td>Tables </td>
                        <td> <%= Request.Browser.Tables %></td>
                </tr>
                <tr>
                        <td>Type </td>
                        <td> <%= Request.Browser.Type %></td>
                </tr>
                <tr>
                        <td>VBScript </td>
                        <td> <%= Request.Browser.VBScript %></td>
                </tr>
                <tr>
                        <td>Version </td>
                        <td> <%= Request.Browser.Version %></td>
                </tr>
                <tr>
                        <td>W3CDomVersion </td>
                        <td> <%= Request.Browser.W3CDomVersion %></td>
                </tr>
                <tr>
                        <td>Win16 </td>
                        <td> <%= Request.Browser.Win16 %></td>
                </tr>
                <tr>
                        <td>Win32 </td>
                        <td> <%= Request.Browser.Win32 %></td>
                </tr>
        </table>

How to find the max identity value in an identity colum using sql server 2008

declare @val as int
select @val = IDENT_CURRENT('table_name')
print @val

Wednesday, April 20, 2011

SQL Server CONVERT() Function

Definition and Usage

The CONVERT() function is a general function for converting data into a new data type.
The CONVERT() function can be used to display date/time data in different formats.

Syntax

CONVERT(data_type(length),data_to_be_converted,style)
Where data_type(length) specifies the target data type (with an optional length), data_to_be_converted contains the value to be converted, and style specifies the output format for the date/time.
The styles that can be used are:
Style IDStyle Format
100 or 0mon dd yyyy hh:miAM (or PM)
101mm/dd/yy
102yy.mm.dd
103dd/mm/yy
104dd.mm.yy
105dd-mm-yy
106dd mon yy
107Mon dd, yy
108hh:mm:ss
109 or 9mon dd yyyy hh:mi:ss:mmmAM (or PM)
110mm-dd-yy
111yy/mm/dd
112yymmdd
113 or 13dd mon yyyy hh:mm:ss:mmm(24h)
114hh:mi:ss:mmm(24h)
120 or 20yyyy-mm-dd hh:mi:ss(24h)
121 or 21yyyy-mm-dd hh:mi:ss.mmm(24h)
126yyyy-mm-ddThh:mm:ss.mmm(no spaces)
130dd mon yyyy hh:mi:ss:mmmAM
131dd/mm/yy hh:mi:ss:mmmAM


Example

The following script uses the CONVERT() function to display different formats. We will use the GETDATE() function to get the current date/time:
CONVERT(VARCHAR(19),GETDATE())
CONVERT(VARCHAR(10),GETDATE(),110)
CONVERT(VARCHAR(11),GETDATE(),106)
CONVERT(VARCHAR(24),GETDATE(),113)
The result would look something like this:
Nov 04 2008 11:45 PM
11-04-2008
04 Nov 08
04 Nov 2008 11:45:34:243

Tuesday, April 19, 2011

Code Snippets – List of C# snippets in VS2008

List of Code Snippets in VS2008 for C#

#if Code snippet for #if
#region Code snippet for #region
attribute Code snippet for attribute using recommended pattern
checked Code snippet for checked block
class Code snippet for class
ctor Code snippet for constructor
~ Code snippet for destructor
cw Code snippet for Console.WriteLine
do Code snippet for do…while loop
else Code snippet for else statement
enum Code snippet for enum
equals Code snippet for implementing Equals() according to guidelines
exception Code snippet for exception
for Code snippet for ‘for’ loop
foreach Code snippet for foreach statement
forr Code snippet for reverse ‘for’ loop
if Code snippet for if statement
indexer Code snippet for indexer
interface Code snippet for interface
invoke Code snippet for safely invoking an event
iterator Code snippet for a simple iterator
iterindex Code snippet for ‘named’ iterator/indexer pair using a nested class
lock Code snippet for lock statement
mbox Code snippet for MessageBox.Show
namespace Code snippet for namespace
prop Code snippet for an automatically implemented property
propg Code snippet for an automatically implemented property with a ‘get’ access or and a private ‘set’ accessor
sim Code snippet for int Main()
struct Code snippet for struct
svm Code snippet for ‘void Main’ method
switch Code snippet for switch statement
try Code snippet for try catch
tryf Code snippet for try finally
unchecked Code snippet for unchecked block
unsafe Code snippet for unsafe statement
using Code snippet for using statement
while Code snippet for while loop

You can see snippet’s keyword typically matches the operator.  So next time you type for or while or try remember to hit TAB-TAB to expand the snippet.  Next time we’ll look at making your own code snippets.


Using Literal Character Strings

A literal string is a sequence of bytes or characters, enclosed within either two single quotes (' ') or two double quotes (" ").
Read Prerequisites for this tutorial and practices if you haven't done so.
Consider the following facts when using literal strings in a SELECT statement:
  1. Literal strings are enclosed in single or double quotation marks.
  2. You can use literal strings just like you normally use a column name in the SELECT statement. The literal string will be displayed in very row of the query result.
  3. Literal strings can be concatenated with another literal string or another column by using function CONCAT.
  4. Special characters (e.g. single or double quotes) in the literal string need to be escaped.
Practice #1: Using a literal string in SELECT statement.
In Firefox (not IE), copy and paste the following SQL to your SQLyog query window. To execute a query, move your cursor anywhere inside the query and then press F9. Note that the SQL needs to end with semi-colon.
-- Use single quotes around literal string
SELECT CategoryID, CategoryName, 'Northwind Category' AS Note
FROM categories;
 -- Use double quotes around literal string
SELECT CategoryID, CategoryName, "Northwind Category" AS Note
FROM categories;
The two queries above produce the same result set. You can use two single quotes or two double quotes but you can't use one single quote and one double quote for a literal string.
Query result set - 8 rows returned:
Literal string in SELECT statement
Practice #2: Concatenate literal strings with columns in SELECT statement.
In Firefox (not IE), copy and paste the following SQL to your SQLyog query window. To execute a query, move your cursor anywhere inside the query and then press F9. Note that the SQL needs to end with semi-colon.
-- Concatenate strings and columns
SELECT CONCAT('Quantity Per Unit for ', ProductName, ' is ', QuantityPerUnit)
        AS "Product Details"
FROM products;
The query above uses function CONCAT to concatenate literal string with column data. MySQL functions are covered in Using Single-Row Functions section.
Query result set - 77 rows returned:
Literal strings are concatenated in SELECT statement
Practice #3: Escape single quote character by backward slash.
In Firefox (not IE), copy and paste the following SQL to your SQLyog query window. To execute a query, move your cursor anywhere inside the query and then press F9. Note that the SQL needs to end with semi-colon.
-- Escape single quote character
SELECT CategoryName, 'Northwind\'s category name' AS Note
FROM categories
Within a string, certain characters have special meaning. Each of these characters needs to be preceded by a backslash \, known as the escape character.
The query above uses a single quote character inside the literal string. Because the literal string is enclosed in two single quotes, we need to escape the one inside the string by using escape character backslash \.
Query result set - 8 rows returned:
Escape single quote in literal string
Practice #4: Use two single quote characters instead of escaping.
In Firefox (not IE), copy and paste the following SQL to your SQLyog query window. To execute a query, move your cursor anywhere inside the query and then press F9. Note that the SQL needs to end with semi-colon.
Alternatively, you can use two single quote characters to mimic the effect of escaping one single quote character.
-- Use two single quote characters to mimic the effect of 
-- escaping one single quote character.
SELECT CategoryName, 'Northwind''s category name' AS Note
FROM categories;
The query above uses two single quotes and produced the same result as the one using escape character in Practice #3.
Query result set - 8 rows returned:
Escape single quote in literal string
Practice #5: Escape double quote character by backward slash.
In Firefox (not IE), copy and paste the following SQL to your SQLyog query window. To execute a query, move your cursor anywhere inside the query and then press F9. Note that the SQL needs to end with semi-colon.
-- Escape double quote character
SELECT CategoryName, "Northwind \"category\" name" AS Note
FROM categories;
The double quote character inside the literal string needs to be escaped because the literal string is enclosed in two double quotes.
Query result set - 8 rows returned:
Escape double quote in literal string
Practice #6: Use two double quote characters instead of escaping.
In Firefox (not IE), copy and paste the following SQL to your SQLyog query window. To execute a query, move your cursor anywhere inside the query and then press F9. Note that the SQL needs to end with semi-colon.
-- Use two double quote characters to mimic the effect of 
-- escaping one double quote.
SELECT CategoryName, "Northwind ""category"" name" AS Note
FROM categories;
The query above uses two double quote characters and produced the same result as the one using escape character in Practice #5.
Query result set - 8 rows returned:
Escape double quote in literal string
Practice #7: One or more single quote characters inside a literal string quoted with two double quotes needs no special treatment and need not to be doubled or escaped.
In Firefox (not IE), copy and paste the following SQL to your SQLyog query window. To execute a query, move your cursor anywhere inside the query and then press F9. Note that the SQL needs to end with semi-colon.
-- A single quote inside a literal string quoted with two double 
-- quotes needs no special treatment and need not to be doubled or escaped.
SELECT CategoryName, "Northwind category's name" AS Note
FROM categories;
The query above uses a single quote inside the literal string that is quoted with two double quotes. The single quote does not need to be escaped.
Query result set - 8 rows returned:
Enclose single quote in double quoted literal string
Practice #8: One or more double quote characters inside a literal string quoted with two single quote characters needs no special treatment and need not to be doubled or escaped.
In Firefox (not IE), copy and paste the following SQL to your SQLyog query window. To execute a query, move your cursor anywhere inside the query and then press F9. Note that the SQL needs to end with semi-colon.
-- double quote characters inside a literal string quoted 
-- with two single quote characters needs no special treatment 
-- and need not to be doubled or escaped.
SELECT CategoryName, 'Northwind "category" name' AS Note
FROM categories;
The query above uses double quotes inside the literal string that is quoted with two single quotes. The double quotes do not need to be escaped.
Query result set - 8 rows returned:
Enclose double quotes in single quoted literal string
Practice #9: Escape backslash itself.
In Firefox (not IE), copy and paste the following SQL to your SQLyog query window. To execute a query, move your cursor anywhere inside the query and then press F9. Note that the SQL needs to end with semi-colon.
-- Add a backslash in the literal string
SELECT CategoryName, 'Northwind \\ category name' AS Note
FROM categories;
The query above displays a backslash in the result. The backslash needs to be escaped by preceding it with another backslash.
Query result set - 8 rows returned:
Escape backslash in literal string
Practice #10: Escape other special characters such as newline character.
In Firefox (not IE), copy and paste the following SQL to your SQLyog query window. To execute a query, move your cursor anywhere inside the query and then press F9. Note that the SQL needs to end with semi-colon.
-- Add line break in the result set. Line break is achieved by using
-- newline character escape sequence \n
SELECT CategoryName, 'Northwind \ncategory \nname' AS Note
FROM categories;
The query above adds a newline in the result set. Newline character is added in by \n in the literal string.
Below is the query result in text view. We switched the result view from grid to text in order to see the multiple lines in the result. Grid view only shows the first line. To switch to text view in SQLyog, highlight anywhere in the result, and then press Ctrl+L on your keyboard.
Query result in text view:
Escape newline character in query result
To see a list of escaped characters in MySQL, click here to go to MySQL online documentation about String data type.