Category: Archive

Engineering notes from 2008–2014: SQL Server scripts, DBA quick-tips, and field notes from the trenches. Preserved as written — the foundation everything since was built on.

  • How to enable or disable ‘sa’ login?

    /* To disable 'sa' Login */
    ALTER LOGIN [sa] DISABLE
    GO
    /* To Enable 'sa' Login */
    ALTER LOGIN [sa] ENABLE
    GO

  • Networking Questions

    What is DNS?

    Domain name system/server is used to translate the IP address into the hostname and hostname into the IP address. DNS is mostly used on the internet and the networks.

    What is DHCP?

    Dynamic host configuration protocol is used to dynamically assign the IP address to the networked computers and devices. DHCP is a network protocol that automatically assigns static and dynamic IP addresses from its own range.

    What is a Router?

    Router is the most important network device that is used to connect two logically and physically different networks. Router defines the short possible route for the data to reach its destination. A router works with built-in intelligent software known as routing table, which helps to determine the route between the two networks.

    What is Gateway?

    A gateway is software or a hardware that is used to connect the local area network with the internet. A gateway is a network entrance point and a router usually works as a gateway.

    What is WLAN?

    WLAN or Wireless local area network is simply a type of network that doesn’t use wired Ethernet connections for networking. WLAN uses wireless network devices such as wireless routers etc.

    What is Subnet Mask?

    A subnet mask is used to determine the number of networks and the number of host computers. Every class of the IP address uses the different range of the subnet mask. Subnet masks allow the IP based networks to be divided into the sub networks for performance and security purposes.

    What is a MAC Address?

    MAC address or Media Access control is a unique identifier of a computer device. The MAC address is provided by the manufacturer of the device. MAC addresses are 12 digital hexadecimal numbers.

    What is an IP Address?

    An IP address is a unique identifier of a computer or network device on the local area network, WAN or on internet. Every host computer on the internet must have a unique IP address. IP addresses on the internet are usually assigned by the local ISPs to which users are connected.

    What is Wifi?

    Wi Fi or wireless fidelity is a base band network technology that is used for the wireless data communication.

    What is WiMax?

    Wi Fi is a next form of the Wi fi. Wi max is a very high speed broadband network technology that is designed for the corporate offices, roaming and home users.

    Name the Seven Layers of OSI Model

    The seven layers of the OSI are Application, Presentation, Sessions, Transport, Network, Data Link and Physical layer.

    What is LDAP?

    Lightweight Directory Access Protocol is used to access the directory services from the Active directory in Windows operation systems.

    What are the standard port numbers for SMTP, POP3, IMAP4, RPC, LDAP, and FTP?

    SMTP – 25, POP3 – 110, IMAP4 – 143, RPC – 135, LDAP, FTP-21, HTTP-80

    What is IPv6?

    IP V6 is a next generation protocol that is used as an expansion of DNS.

    What is UDP?

    UDP or user datagram protocol is a connectionless protocol that is used to transfer the data without any error handling.

    What is Firewall?

    A firewall is usually a software program that is installed on the network server or gateway. The purpose of the firewall is to protect the network resources from the intruders and unauthorized persons.

    What is Virtual Private Network (VPN) and how does it work?

    VPN or virtual private network is used to connect two networks by means internet. VPN uses PPTP (point to point tunneling protocol) and other security procedures to make a secure tunnel on internet.

    Define VOIP

    VOIP or voice over internet protocol is a technology that uses IP based networks such as internet or private networks to transmit the voice communication.

    Define Bluetooth Technology

    Bluetooth is a short range wireless technology that uses radio waves for communication. Many mobile phones, laptops, MP3 players have built in features of the Bluetooth.

    What is a RAS server?

    RAS or remote access server allows you to remote dial in through the desktop computers, laptops and GSM mobile phones.

    What’s a Frame Relay?

    Frame relay is high speed data communication technology that operates at the physical and data link layers of the OSI model. Frame relay uses frames for data transmission in a network.

  • What is the Global.asax file?

    What is the Global.asax file?

    The Global.asax file (also known as the ASP.NET application file) is an optional file that is located in the application’s root directory and is the ASP.NET counterpart of the Global.asa of ASP. This file exposes the application and session level events in ASP.NET and provides a gateway to all the application and the session level events in ASP.NET. This file can be used to implement the important application and session level events such as Application_Start, Application_End, Session_Start, Session_End, etc. This article provides an overview of the Global.asax file, the events stored in this file and how we can perform application wide tasks with the help of this file.

    According to MSDN, “The Global.asax file, also known as the ASP.NET application file, is an optional file that contains code for responding to application-level events raised by ASP.NET.” The Global.asax file is parsed and dynamically compiled by ASP.NET into a .NET Framework class the first time any resource or URL within its application namespace is activated or requested. Whenever the application is requested for the first time, the Global.asax file is parsed and compiled to a class that extends the HttpApplication class. When the Global.asax file changes, the framework reboots the application and the Application_OnStart event is fired once again when the next request comes in. Note that the Global.asax file does not need recompilation if no changes have been made to it. There can be only one Global.asax file per application and it should be located in the application’s root directory only.

    The following are some of the important events in the Global.asax file.

    · Application_Init

    · Application_Start

    · Session_Start

    · Application_BeginRequest

    · Application_EndRequest

    · Application_AuthenticateRequest

    · Application_Error

    · Session_End

    · Application_End

    The purpose of these event handlers is discussed in this section below.

    Application_Init

    The Application_Init event is fired when an application initializes the first time.

    Application_Start

    The Application_Start event is fired the first time when an application starts.

    Session_Start

    The Session_Start event is fired the first time when a user’s session is started. This typically contains for session initialization logic code.

    Application_BeginRequest

    The Application_BeginRequest event is fired each time a new request comes in.

    Application_EndRequest

    The Application_EndRequest event is fired when the application terminates.

    Application_AuthenticateRequest

    The Application_AuthenticateRequest event indicates that a request is ready to be authenticated. If you are using Forms Authentication, this event can be used to check for the user’s roles and rights.

    Application_Error

    The Application_Error event is fired when an unhandled error occurs within the application.

    Session_End

    The Session_End Event is fired whenever a single user Session ends or times out.

    Application_End

    The Application_End event is last event of its kind that is fired when the application ends or times out. It typically contains application cleanup logic.

  • The Basics of Hyper-Threading: What is it?

    The Basics of Hyper-Threading: What is it?

    Modern processors can only handle one instruction from one program at any given point in time. Each instruction that is sent to the processor is called a thread. What I mean is that even though it looks like you’re multitasking with your computer (running more then one program at a time) you’re really not.

    The CPU will divide it’s time and power evenly between all the programs by switching back and forth. This little charade of switching back and forth tricks the end user (you and me) and gives us the sense of multitasking.

    Dual CPU based systems can work on two independent threads of information from the software but each processor is still limited at working on one thread at any given moment though. The software must be able to dish out two separate pieces of information like Win2000 or Adobe Photoshop for a dual processor system to be really used, by the way.

    So what’s new with the Pentium4 3.06GHz processor?

    The Pentium 4 3.06 GHz processor is the first Intel desktop processor in history that can process two independent threads at the same time. With a SMT (Simultaneous Multi-Thread) enabled OS like Win2000/XP, Linux, etc. the operation system will identify the P4 3.06 GHz CPU as two logical processors that share the single physical CPU’s resources. A physical processor can be thought of as the chip itself, whereas a logical processor is what the computer sees – with Hyper-Threading enabled the computer can have one physical processor installed in the motherboard, but the computer will see two logical processors, and treat the system as if there were actually two processors.

    Even when we put a regular processor under 100% load, we’re never fully utilizing 100% of the execution units. With a HyperThreading enabled processor those spare execution units can used towards computing other things now.

    In the last HyperThreading enabled processor, both threads are simultaneously being computed, and the CPU’s efficiency has increased from around 50% to over 90%!

    The last example is of dual HyperThreading enabled processors which can work on four independent threads at the same time. Again CPU efficiency is around 90% (and in this case there would be four logical processors, and two physical processors).

    While this all sounds very good in the above example, it’s also about the most ideal situation ever – so let’s get back to the real world.

    If you were to run two pieces of software that are completely different, and use different execution units, your system performance should get a noticeable boost however!

    The operating system will also play a key role in how well HyperThreading works. The OS assigns operations to the independent logical processors, and so if it’s determined that one of the logical CPU’s is to remain idle, the OS will issue a HALT command to the free logical processor thus devoting all of the other system resources to the working logical processor.

    As you can see, HyperThreading has the potential to significantly boost system performance under certain circumstances. From Xeon/HyperThreading test results over at Anandtech you get a feel that HyperThreading Technology is still in it’s infancy in terms of real added value across the board. As it stands now, the performance that HT brings to the table is still very application specific. Some programs will notice a performance boost, and in some cases, other programs will see a performance hit with HT enabled.

    As more and more software is written specifically for HyperThreading, the performance differences will grow larger. It didn’t take long for software developers to adopt SSE2, hopefully they’ll jump on the HyperThreading bandwagon quickly and the consumer will see the benefit of this this ingenuous technology quickly

  • XP_cmdshell extended stored procedure (Execute Winows commands)

    xp_cmdshell

    Executes a given command string or batch file as an operating-system command shell and returns any output as rows of text.

    Permission/Rights: Only SysAdmin fixed role can execute it.

    Syntax

    xp_cmdshell {‘command_string‘} [, no_output]

    Arguments

    ‘command_string‘

    Is the command string to execute at the operating-system command shell or from DOS prompt. command_string is varchar(255) or nvarchar(4000), with no default.

    command_string cannot contain more than one set of double quotation marks.

    A single pair of quotation marks is necessary if any spaces are present in the file paths or program names referenced by command_string.

    If you have trouble with embedded spaces, consider using FAT 8.3 file names as a workaround.

    no_output

    Is an optional parameter executing the given command_string, and does not return any output to the client.

    Examples
    xp_cmdshell 'dir *.jpg'

    Executing this xp_cmdshell statement returns the following result set:

    xp_cmdshell 'dir *.exe', NO_OUTPUT

    Here is the result:

    The command(s) completed successfully.

    <!–[if gte vml 1]&gt; &lt;![endif]–><!–[if !vml]–><!–[endif]–>

    Examples
    Copy File
    EXEC xp_cmdshell 'copy c:\sqldumps\jshah143.bak \\server2\backups\jshah143.bak',  NO_OUTPUT
     
    Use return status

    In this example, the xp_cmdshell extended stored procedure also suggests return status. The return code value is stored in the variable @result.

    DECLARE @result int
    EXEC @result = xp_cmdshell 'dir *.exe'
    IF (@result = 0)
       PRINT 'Success'
    ELSE
       PRINT 'Failure'

     

    Pass the parameter to batch file

    DECLARE @sourcepath VARCHAR(100)
    DECLARE @destinationpath VARCHAR(1000)
    SET @sourcepath = ' c:\sqldumps\jshah143.bak '
    SET @destinationpath = '\\server2\backups\jshah143.bak'
     
    SET @CMDSQL = 'c:copyfile.bat' + @sourcepath + @destinationpath
    EXEC master..XP_CMDShell @CMDSQL