Thursday, January 28, 2010

Configure Windows XP to Automatically Login

1. At a command prompt, type "control userpasswords2" and press Enter to open the Windows User Accounts application.
2. On the Users tab, clear the Users Must Enter A User Name And Password To Use This Computer check box and then click OK.
3. In the Automatically Log On dialog box that appears, type the user name and password for the account you want to be logged on each time you start your computer.

Saturday, January 16, 2010

How to remote connect to SQL Server 2005 by Specific TCP Port

SQL Server 2005 is not configured to accept remote connections. By default.

To allow remote connections, you have to complete all the following steps:

  • Enable remote connections on the instance of SQL Server that you want to connect to from a remote computer.
  • Configure SQL Server to Listen on a Specific TCP Port.
  • To open a port in Windows Firewall.
  • Connect to SQL Server 2005 by using MS SQL Server Management Studio with port number.

Enable remote connections on the instance of SQL Server that you want to connect to from a remote computer.
  1. Click Start, point to Programs, point to Microsoft SQL Server 2005, point to Configuration Tools, and then click SQL Server Surface Area Configuration.
  2. On the SQL Server 2005 Surface Area Configuration page, click Surface Area Configuration for Services and Connections.
  3. On the Surface Area Configuration for Services and Connections page, expand Database Engine, click Remote Connections, click Local and remote connections, click the appropriate protocol to enable for your environment, and then click Apply.

    Note Click OK when you receive the following message:
    Changes to Connection Settings will not take effect until you restart the Database Engine service.
  4. On the Surface Area Configuration for Services and Connections page, expand Database Engine, click Service, click Stop, wait until the MSSQLSERVER service stops, and then click Start to restart the MSSQLSERVER service.
Configure SQL Server to Listen on a Specific TCP Port
  1. In SQL Server Configuration Manager, in the console pane, expand SQL Server 2005 Network Configuration, expand Protocols for <instance name>, and then double-click TCP/IP.
  2. In the TCP/IP Properties dialog box, on the IP Addresses tab, all the IP addresses available in your computer is listed in here ... IP1, IP2, up to IPAll. Right-click one of address, and then click Properties to identify the IP address that you wish to configure.
  3. The TCP Dynamic Ports dialog box contains 0, indicating the Database Engine is listening on dynamic ports. Which means they select an available port when the SQL Server service is started. To disable listening dynamic port you can delete the 0 and left the blank.
  4. In the IPn Properties area box, in the TCP Port box, type the port number you wish this IP address to listen on, and then click OK.
  5. In the console pane, click SQL Server 2005 Services.
  6. In the details pane, right-click SQL Server (<instance name>) and then click restart, to stop and restart SQL Server.

To open a port in Windows Firewall
  1. On the Start menu, click Control Panel.
  2. In Control Panel, click Network and Internet Connections, and then open Windows Firewall.
  3. In Windows Firewall, click the Exceptions tab, and then click Add Port.
  4. In the Add a Port dialog box, in the Name box, type SQL Server <instanceName>.
  5. In the Port number box, type the port number of the Database Engine instance. Use 1433 for the default instance. Type 1500 if you are configuring a named instance and configured a fixed port to 1500 . Verify that TCP is selected, and then click OK
Connect to SQL Server 2005 by using MS SQL Server Management Studio with port number
  1. Open SQL Server Management Studio, In the Connect to Server dialog box, in the Server Name box type xxx.xxx.xxx.xxx\SQLEXPRESS,1500.
  2. type user name and password to connect to server.


Thursday, December 17, 2009

Windows Remote Desktop Web Connection ActiveX Reference

This articel help you understand how to use javascript create a customize windwos remote desktop web connection.
you can use this technic connect to your server desktop anywhere and the IE browser is all you need.
 
// Declare MsRdpClient object in the web page
    <OBJECT language="vbscript" ID="MsRdpClient" CLASSID="CLSID:7584c670-2274-4efb-b00b-d6aaba6d3850"
        onerror="OnControlLoadError"
        onreadystatechange="OnControlLoad"
        CODEBASE="msrdp.cab#version=5,2,3790,3959"
        WIDTH=<% resWidth = Request.QueryString("rW")
            if  resWidth < 200 or resWidth > 1600 then
               resWidth = 800
            end if
            Response.Write resWidth %>
        HEIGHT=<% resHeight = Request.QueryString("rH")
            if  resHeight < 200 or resHeight > 1200 then
               resHeight = 600
            end if
            Response.Write resHeight %>
    </OBJECT>
 
// Some Necessary input fields in web page
    Domain Name: <input type="text" name="Domain" id="editDomain">
    Screen Resolution:
    <select size="1" name="comboResolution" id=comboRes class="topspace">
        <option selected value="1"><ID id=option1>Full Screen</ID></option>
        <option value="2"><ID id=option2>640 x 480</ID></option>
        ....
        <option value="7"><ID id=option6>1600 x 1200</ID></option>
    </select>
   
    <input type="submit" id=connectbutton value="Connect" disabled="true" name="ButtonLogin" OnClick="RdpConnect">
 
// Validate MsRdpClient ActiveX is ready to load
    function onControlLoad
    {
       var control = document.getElementById("MsRdpClient");
       if(control == null)
       {
          if(control.readyState == 4)
          {
             document.getElementById("connectButton").disabled = false;
          }
       }
    }

// invok  connection to MsRdpClient object
function RdpConnect()
{
    MsRdpClient.Server="Server";
    MsRdpClient.Domain="Domain";
    MsRdpClient.UserName="user";
    MsRdpClient.AdvancedSettings2.ClearTextpassword="password";
    MsRdpClient.AdvancedSettings2.RDPPort = 3389;
    MsRdpClient.FullScreen=1;
    MsRdpClient.Width=1024;
    MsRdpClient.Height=768;
    MsRdpClient.DesktopWidth=1024;
    MsRdpClient.DesktopHeight=768;
    MsRdpClient.Connect();
}


MsRdpClient OCX Methods and controls reference:
    MsRdpClient.AdvancedSettings.PluginDlls
    MsRdpClient.AdvancedSettings2.AcceleratorPassthrough
    MsRdpClient.AdvancedSettings2.BitmapCacheSize
    MsRdpClient.AdvancedSettings2.BitmapPersistence
    MsRdpClient.AdvancedSettings2.BitmapVirtualCache16BppSize
    MsRdpClient.AdvancedSettings2.BitmapVirtualCache24BppSize
    MsRdpClient.AdvancedSettings2.BitmapVirtualCacheSize
    MsRdpClient.AdvancedSettings2.ClearTextPassword
    MsRdpClient.AdvancedSettings2.ConnectToServerConsole
    MsRdpClient.AdvancedSettings2.DedicatedTerminal
    MsRdpClient.AdvancedSettings2.DisableCtrlAltDel
    MsRdpClient.AdvancedSettings2.DisplayConnectionBar
    MsRdpClient.AdvancedSettings2.DoubleClickDetect
    MsRdpClient.AdvancedSettings2.EnableAutoReconnect
    MsRdpClient.AdvancedSettings2.EnableMouse
    MsRdpClient.AdvancedSettings2.EnableWindowsKey
    MsRdpClient.AdvancedSettings2.FullScreen
    MsRdpClient.AdvancedSettings2.GrabFocusOnConnect
    MsRdpClient.AdvancedSettings2.HotKeyAltEsc
    MsRdpClient.AdvancedSettings2.HotKeyAltShiftTab
    MsRdpClient.AdvancedSettings2.HotKeyAltSpace
    MsRdpClient.AdvancedSettings2.HotKeyAltTab
    MsRdpClient.AdvancedSettings2.HotKeyCtrlAltDel
    MsRdpClient.AdvancedSettings2.HotKeyCtrlEsc
    MsRdpClient.AdvancedSettings2.InputEventsAtOnce
    MsRdpClient.AdvancedSettings2.KeepAliveInterval
    MsRdpClient.AdvancedSettings2.KeyboardType
    MsRdpClient.AdvancedSettings2.MaxEventCount
    MsRdpClient.AdvancedSettings2.MaximizeShell
    MsRdpClient.AdvancedSettings2.MaxReconnectAttempts
    MsRdpClient.AdvancedSettings2.MinInputSendInterval
    MsRdpClient.AdvancedSettings2.MinutesToIdleTimeout
    MsRdpClient.AdvancedSettings2.NumBitmapCaches
    MsRdpClient.AdvancedSettings2.OrderDrawThreshold
    MsRdpClient.AdvancedSettings2.OverallConnectionTimeout
    MsRdpClient.AdvancedSettings2.PerformanceFlags
    MsRdpClient.AdvancedSettings2.PersistCacheDirectory
    MsRdpClient.AdvancedSettings2.PinConnectionBar
    MsRdpClient.AdvancedSettings2.RdpdrClipCleanTempDirString
    MsRdpClient.AdvancedSettings2.RdpdrClipPasteInfoString
    MsRdpClient.AdvancedSettings2.RdpdrLocalPrintingDocName
    MsRdpClient.AdvancedSettings2.RDPPort
    MsRdpClient.AdvancedSettings2.RedirectDrives
    MsRdpClient.AdvancedSettings2.RedirectPorts
    MsRdpClient.AdvancedSettings2.RedirectPrinters
    MsRdpClient.AdvancedSettings2.RedirectSmartCards
    MsRdpClient.AdvancedSettings2.ScaleBitmapCachesByBPP
    MsRdpClient.AdvancedSettings2.ShadowBitmap
    MsRdpClient.AdvancedSettings2.ShutdownTimeout
    MsRdpClient.AdvancedSettings2.SingleConnectionTimeout
    MsRdpClient.AdvancedSettings2.SmartSizing
    MsRdpClient.AdvancedSettings2.SmoothScroll
    MsRdpClient.AdvancedSettings3.ConnectionBarShowMinimizeButton
    MsRdpClient.AdvancedSettings3.ConnectionBarShowRestoreButton
    MsRdpClient.ColorDepth
    MsRdpClient.SecuredSettings.AudioRedirectionMode
    MsRdpClient.SecuredSettings.KeyboardHookMode
    MsRdpClient.SecuredSettings.StartProgram
    MsRdpClient.SecuredSettings.WorkDir


Related Links:
Installing Remote Desktop Web Connection in Windows XP
 
 

Sunday, November 29, 2009

ASP.NET WebService Samples

// Calling WebService Function for javascript
WebServiceObj.GetYourFunctionName(param1, param2, ..., onSucceeded, onFailed, userContext);

/**
* WebService onSuccess Callback function for AJAX.
* @param {Object} result               Can be any types return from WebService Function.
* @param {String} userContext      String can be pass into OnSucceeded or OnFailed Callback Function.
* @param {String} methodName    The WebService Name you called.
*/

function OnSucceeded(result, userContext, methodName)
{
    if (methodName == "GetSessionValue")
    {
        displayElement.innerHTML = "Current session state value: " + result;
    }
}
 
/**
* WebService onFailed Callback function for AJAX.
* @param {Object} result              The value retrun from WebService Function.
* @param {String} userContext     Any String you want pass into callback functions.
* @param {String} methodName   The WebService Function name you calling.
*/

function OnFailed(error, userContext, methodName)
{
    var stackTrace = error.get_stackTrace();
    var message = error.get_message();
    var statusCode = error.get_statusCode();
    var exceptionType = error.get_exceptionType();
    var timedout = error.get_timedOut();
    ...
    ...
}
 
 
Related Links:


SQL Server Collation Name

COLLATE  SQL_SortRules[_Pref]_CPCodepage_<ComparisonStyle>
Sample
COLLATE Chinese_Taiwan_Stroke
COLLATE Chinese_Taiwan_Stroke_BIN
COLLATE Chinese_Taiwan_Stroke_CI_AS
COLLATE Chinese_Taiwan_Bopomofo_CS_AI

SortRules
A string identifying the alphabet or language whose sorting rules are applied when dictionary sorting is specified.
Examples are Latin1_General, Polish or
Chinese_Taiwan.
Pref
Specifies uppercase preference.

Codepage
Specifies a one- to four-digit number that identifies the code page used by the collation. CP1 specifies code page 1252, for all other code pages the complete code page number is specified. For example, CP1251 specifies code page 1251 and CP850 specifies code page 850.

CaseSensitivityCI specifies case-insensitive, CS specifies case-sensitive.
AccentSensitivity
AI specifies accent-insensitive, AS specifies accent-sensitive.

BIN
Specifies the binary sort order to be used.

SQL Server Collation Name (Transact-SQL)
SQL Server 2005 Books Online (September 2007) - Collation Settings in Setup

Monday, November 9, 2009

Retrieve Last Inserted Identity of Record

SQL SERVER

March 25, 2007 by pinaldave

SELECT @@IDENTITY
It returns the last IDENTITY value produced on a connection, regardless of the table that produced the value, and regardless of the scope of the statement that produced the value.
@@IDENTITY will return the last identity value entered into a table in your current session. While @@IDENTITY is limited to the current session, it is not limited to the current scope. If you have a trigger on a table that causes an identity to be created in another table, you will get the identity that was created last, even if it was the trigger that created it.
SELECT SCOPE_IDENTITY()
It returns the last IDENTITY value produced on a connection and by a statement in the same scope, regardless of the table that produced the value.
SCOPE_IDENTITY(), like @@IDENTITY, will return the last identity value created in the current session, but it will also limit it to your current scope as well. In other words, it will return the last identity value that you explicitly created, rather than any identity that was created by a trigger or a user defined function.
SELECT IDENT_CURRENT(’tablename’)
It returns the last IDENTITY value produced in a table, regardless of the connection that created the value, and regardless of the scope of the statement that produced the value.
IDENT_CURRENT is not limited by scope and session; it is limited to a specified table. IDENT_CURRENT returns the identity value generated for a specific table in any session and any scope.
To avoid the potential problems associated with adding a trigger later on, always use SCOPE_IDENTITY() to return the identity of the recently added row in your T SQL Statement or Stored Procedure.
Source: Pinal Dave (http://www.SQLAuthority.com)

MySQL

If you insert a record into a table that contains an AUTO_INCREMENT column, you can obtain the value stored into that column by calling the mysql_insert_id() function or by executing a SELECT LAST_INSERT_ID() statement with mysql_query() and retrieving the value from the result set returned by the statement. .
If you want to use the ID that was generated for one table and insert it into a second table, you can use SQL statements like this:
INSERT INTO foo (auto,text)
    VALUES(NULL,'text');         # generate ID by inserting NULL
INSERT INTO foo2 (id,text)
    VALUES(LAST_INSERT_ID(),'text');  # use ID in second table


You can check from your C applications whether a value was stored in an AUTO_INCREMENT column by executing the following code (which assumes that you've checked that the statement succeeded). It determines whether the query was an INSERT with an AUTO_INCREMENT index:
if ((result = mysql_store_result(&mysql)) == 0 &&
    mysql_field_count(&mysql) == 0 &&
    mysql_insert_id(&mysql) != 0)
{
    used_id = mysql_insert_id(&mysql);
}
Source: http://dev.mysql.com/doc/refman/5.0/en/getting-unique-id.html
 
 

Sunday, October 25, 2009

retrieve the horizontal resolution for a video display, or printer

Device-Independent Bitmaps
A device-independent bitmap (DIB) contains a color table. A color table describes how pixel values correspond to RGB color values, which describe colors that are produced by emitting light. Thus, a DIB can achieve the proper color scheme on any device. A DIB contains the following color and dimension information:
  • The color format of the device on which the rectangular image was created.
  • The resolution of the device on which the rectangular image was created.
  • The palette for the device on which the image was created.
  • An array of bits that maps red, green, blue (RGB) triplets to pixels in the rectangular image.
  • A data-compression identifier that indicates the data compression scheme (if any) used to reduce the size of the array of bits.
The color and dimension information is stored in a BITMAPINFO structure, which consists of a BITMAPINFOHEADER structure followed by two or more RGBQUAD structures. The BITMAPINFOHEADER structure specifies the dimensions of the pixel rectangle, describes the device's color technology, and identifies the compression schemes used to reduce the size of the bitmap. The RGBQUAD structures identify the colors that appear in the pixel rectangle.
There are two varieties of DIBs:
  • A bottom-up DIB, in which the origin lies at the lower-left corner.
  • A top-down DIB, in which the origin lies at the upper-left corner.
If the height of a DIB, as indicated by the Height member of the bitmap information header structure, is a positive value, it is a bottom-up DIB; if the height is a negative value, it is a top-down DIB. Top-down DIBs cannot be compressed.
The color format is specified in terms of a count of color planes and color bits. The count of color planes is always 1; the count of color bits is 1 for monochrome bitmaps, 4 for VGA bitmaps, and 8, 16, 24, or 32 for bitmaps on other color devices. An application retrieves the number of color bits that a particular display (or printer) uses by calling the GetDeviceCaps function, specifying BITSPIXEL as the second argument.
The resolution of a display device is specified in pixels-per-meter. An application can retrieve the horizontal resolution for a video display, or printer, by following this three-step process.
  1. Call the GetDeviceCaps function, specifying HORZRES as the second argument.
  2. Call GetDeviceCaps a second time, specifying HORZSIZE as the second argument.
  3. Divide the first return value by the second return value.
The application can retrieve the vertical resolution by using the same three-step process with different parameters: VERTRES in place of HORZRES, and VERTSIZE in place of HORZSIZE.
The palette is represented by an array of RGBQUAD structures that specify the red, green, and blue intensity components for each color in a display device's color palette. Each color index in the palette array maps to a specific pixel in the rectangular region associated with the bitmap. The size of this array, in bits, is equivalent to the width of the rectangle, in pixels, multiplied by the height of the rectangle, in pixels, multiplied by the count of color bits for the device. An application can retrieve the size of the device's palette by calling the GetDeviceCaps function, specifying NUMCOLORS as the second argument.
Windows supports the compression of the palette array for 8-bpp and 4-bpp bottom-up DIBs. These arrays can be compressed by using the run-length encoding (RLE) scheme. The RLE scheme uses 2-byte values, the first byte specifying the number of consecutive pixels that use a color index and the second byte specifying the index. For more information about bitmap compression, see the description of the BITMAPINFOHEADER, BITMAPFILEHEADER, BITMAPV4HEADER, and BITMAPV5HEADER structures.
An application can create a DIB from a DDB by initializing the required structures and calling the GetDIBits function. To determine whether a device supports this function, call the GetDeviceCaps function, specifying RC_DI_BITMAP as the RASTERCAPS flag.
An application that needs to copy a bitmap can use TransparentBlt to copy all pixels in a source bitmap to a destination bitmap except those pixels that match the transparent color.
An application can use a DIB to set pixels on the display device by calling the SetDIBitsToDevice or the StretchDIBits function. To determine whether a device supports the SetDIBitsToDevice function, call the GetDeviceCaps function, specifying RC_DIBTODEV as the RASTERCAPS flag. Specify RC_STRETCHDIB as the RASTERCAPS flag to determine if the device supports StretchDIBits.
An application that simply needs to display a pre-existing DIB can use the SetDIBitsToDevice function. For example, a spreadsheet application can open existing charts and display them in a window by using the SetDIBitsToDevice function. To repeatedly redraw a bitmap in a window, however, the application should use the BitBlt function. For example, a multimedia application that combines animated graphics with sound would benefit from calling the BitBlt function because it executes faster than SetDIBitsToDevice.