Find out what’s going on with your SQL Servers

Have your SQL Servers ever gone mental on you all of a sudden, and you wish you could quickly see an overview of what was running at the time?

I just found these useful queries on a Spiceworks forum.

The first one will show you what is currently being executed on your server:

SELECT s.session_id AS SessionID,
 s.login_time AS LoginTime,
 s.[host_name] AS HostName,
 s.[program_name] AS ProgramName,
 s.login_name AS LoginName,
 s.[status] AS SessionStatus,
 st. AS SQLText,
 (s.cpu_time / 1000) AS CPUTimeInSec,
 (s.memory_usage * 8) AS MemoryUsageKB,
 (CAST(s.total_scheduled_time AS FLOAT) / 1000) AS TotalScheduledTimeInSec,
 (CAST(s.total_elapsed_time AS FLOAT) / 1000) AS ElapsedTimeInSec,
 s.reads AS ReadsThisSession,
 s.writes AS WritesThisSession,
 s.logical_reads AS LogicalReads,
 CASE s.transaction_isolation_level
 WHEN 0 THEN 'Unspecified'
 WHEN 1 THEN 'ReadUncommitted'
 WHEN 2 THEN 'ReadCommitted'
 WHEN 3 THEN 'Repeatable'
 WHEN 4 THEN 'Serializable'
 WHEN 5 THEN 'Snapshot'
 END AS TransactionIsolationLevel,
 s.row_count AS RowsReturnedSoFar,
 c.net_transport AS ConnectionProtocol,
 c.num_reads AS PacketReadsThisConnection,
 c.num_writes AS PacketWritesThisConnection,
 c.client_net_address AS RemoteHostIP,
 c.local_net_address AS LocalConnectionIP
 FROM sys.dm_exec_sessions s INNER JOIN sys.dm_exec_connections c
 ON s.session_id = c.session_id
 CROSS APPLY sys.dm_exec_sql_text(c.most_recent_sql_handle) AS st
 WHERE s.is_user_process = 1
 ORDER BY ElapsedTimeInSec DESC

This next one can show blocking processes… you can use the blocking session ID to track down the other processes:

SELECT dm_ws.wait_duration_ms,
 dm_ws.wait_type,
 dm_es.status,
 dm_t.TEXT,
 dm_ws.session_ID,
 dm_es.cpu_time,
 dm_es.memory_usage,
 dm_es.logical_reads,
 dm_es.total_elapsed_time,
 dm_es.program_name,
 DB_NAME(dm_r.database_id) DatabaseName,
 dm_ws.blocking_session_id,
 dm_r.wait_resource,
 dm_es.login_name,
 dm_r.command,
 dm_r.last_wait_type
 FROM sys.dm_os_waiting_tasks dm_ws
 INNER JOIN sys.dm_exec_requests dm_r ON dm_ws.session_id = dm_r.session_id
 INNER JOIN sys.dm_exec_sessions dm_es ON dm_es.session_id = dm_r.session_id
 CROSS APPLY sys.dm_exec_sql_text (dm_r.sql_handle) dm_t
 WHERE dm_es.is_user_process = 1

Reference

Changing a UCC/SAN Certificate and Re-Issuing from GoDaddy

Scenario

When initially setting up the Unified Communications Certificate (UCC) certificate for Exchange, autodiscover.domain.com was not added as a Subject Alternative Name (SAN).

You need to enable autodiscover in Exchange 2010 for external devices (iOS, laptop Outlook etc.) without a security warning.

Solution

The certificate needs to be updated with autodiscover.domain.com as a SAN.

These instructions pertain to a GoDaddy certificate – other providers will likely be different.

An A record had already been created in the domain’s DNS zone pointing autodiscover.domain.com to the public IP address of the router.

As it turns out, GoDaddy offer the opportunity to drop and replace SANs from their UCC certificates at will – with domain ownership validation required if any are added, of course.

Here are the steps:

[Read more…]

RAID Controller Software for the Dell PERC 6/i RAID Card

Problem

You have purchased a Dell PERC 6/i RAID Card separately, and are using it in a non-Dell server, so you cannot use the Dell Management software to manage the card.

Solution

The Dell PERC 6/i RAID Card is just a rebadged LSI MegaRAID card, so download and install the latest version of LSI’s MegaRAID Storage Manager software – currently on version 12.05.03.00:

http://www.lsi.com/downloads/Public/MegaRAID%20Common%20Files/12.05.03.00_Windows_MSM.zip

For other software – like VIBs for VMware ESXi, look under the Support & Downloads section here:

http://www.lsi.com/products/storagecomponents/Pages/MegaRAIDSAS9265-8i.aspx

Once installed, you can set up Alerts from the Tools > Monitor Configure Alerts menu:

Adding a node to a SQL Server 2008 R2 Failover Cluster using Server 2008 R2

Scenario

You’ve successfully installed and configured a SAN, a Failover Cluster and an instance of SQL Server 2008 R2 on one node. Now you need add another node to this cluster so the SQL Server instance can failover.

Solution

  1. From the setup menu, select Installation > Add node to a SQL Server failover cluster:

  2. Click OK after the first set of checks:
    [Read more…]

Installing SQL Server 2008 R2 on a Failover Cluster using Server 2008 R2

Scenario

You’ve configured a Failover Cluster using Server 2008 R2, and now you want to install SQL Server 2008 R2.

Solution

Changes

A few changes were made to the simple Failover Cluster that was previously configured:

  • Several LUNs were added to the FreeNAS VM so separate disks could be used for each function:
  • 3 x Network Interface Cards (NICs) were configured on each node, each on a different subnet:
    • LAN: 10.10.10.0/24
    • SAN: 10.10.20.0/24
    • Heartbeat: 10.10.30.0/24
  • The FreeNAS interface was configured on the SAN subnet (10.10.20.220).

This time round, the Failover Cluster Validation Report didn’t have a single warning; all green ticks 😉

[Read more…]

Check IIS Application Pool Identity using C#

To check the IIS Application Pool Identity using C#, use the System.Security.Principal class:

using System.Security.Principal;

then add the following code to the Page_Load method:

WindowsIdentity id = WindowsIdentity.GetCurrent();
Response.Write("IIS Application Pool Identity
"); Response.Write("Name: " + id.Name + " ");

Using the DHCP Split-Scope Wizard on Server 2008 R2

Problem

You want to provide some fault tolerance for DHCP, so you plan to add another DHCP server to your network.

You used to have to set up the scopes and exclusions manually, but now you can use the Split-Scope wizard using Server 2008 R2.

[Read more…]

Predefined DHCP Options for VOIP on Server 2008 R2

Problem

You need to set some Predefined Options on your DHCP server to allow your VOIP handsets to connect to the phone system etc.

[Read more…]

The Microsoft SQL Server Express Edition installer returned error code 2064843076

Scenario

You’ve just tried to install VMware vCenter with the option to use SQL Server Express, but the installation fails with the following error:

The Microsoft SQL Server Express Edition installer returned error code ‘2064843076’

Solution

  1. Click Explore Media to open an Explorer window:
  2.  Right-click autorun.exe and select Run as administrator:
  3. Every process that is started from the autorun screen will now have full admin rights, so SQL Server will install fine.

Display owner of Maintenance Plans using SQL Server 2008 R2

Whilst troubleshooting an issue with backups, I wanted to check the owner of all Maintenance Plans.

I found the following query that does just that:

SELECT sj.name AS JobName,
CASE WHEN sj.[Enabled] = 1
THEN 'Yes'
ELSE 'No'
END AS JobIsEnabled,
sl.name AS OwnerName
FROM msdb.dbo.sysjobs AS sj INNER JOIN master.dbo.syslogins AS sl
ON sj.owner_sid = sl.sid
ORDER BY JobName