Check last database restore date/time using SQL Server

Use one of the following scripts.

The first script is quick and simple:

SELECT *
FROM MSDB..RestoreHistory WITH (nolock)
WHERE destination_database_name = DB_NAME()
ORDER BY restore_date DESC

The second script also shows the backup file used during the restore:

SELECT [rs].[destination_database_name],
[rs].[restore_date],
[bs].[backup_start_date],
[bs].[backup_finish_date],
[bs].[database_name] as [source_database_name],
[bmf].[physical_device_name] as [backup_file_used_for_restore]
FROM msdb..restorehistory rs
INNER JOIN msdb..backupset bs
ON [rs].[backup_set_id] = [bs].[backup_set_id]
INNER JOIN msdb..backupmediafamily bmf
ON [bs].[media_set_id] = [bmf].[media_set_id]
ORDER BY [rs].[restore_date] DESC

Source:

Get Current Database Names and IDs in SQL Server

-- Get Current DatabaseID
SELECT DB_ID() DatabaseID;

-- Get Current DatabaseName
SELECT DB_NAME() DatabaseName;

-- Get DatabaseName from DatabaseID
SELECT DB_NAME(4) DatabaseID;

-- Get DatabaseID from DatabaseName
SELECT DB_ID('tempdb') DatabaseName;

-- Get all DatabaseName and DBID
SELECT name,database_id
FROM sys.databases;

Sourcehttp://blog.sqlauthority.com/2011/01/13/sql-server-a-quick-note-on-db_id-and-db_name-get-current-database-id-get-current-database-name/

Adding a new port to a HP Network Team

Problem

A port has died on your NIC and is showing as disconnected in your HP Network Team. The Network Team is no longer redundant.

Solution

You need to add a new port and drop the disconnected port, without affecting the overall settings:

[Read more…]

Differences between IISReset and Recycling Application Pools

I have just read an excellent post on the differences between IISReset and Recycling Application Pools.

Read the post here: http://fullsocrates.wordpress.com/2012/07/25/iisreset-vs-recycling-application-pools/

Task Scheduler failed to start task for user. Additional Data: Error Value: 2147943645

Problem

You scheduled a task, but it failed to run with Error Value: 2147943645
Task-Scheduler-Failed-2147943645_001

Log Name: Microsoft-Windows-TaskScheduler/Operational
Source: Microsoft-Windows-TaskScheduler
Date: 17/01/2013 04:00:00
Event ID: 101
Task Category: Task Start Failed
Level: Error
Keywords:
User: SYSTEM
Computer: [removed]
Description:
Task Scheduler failed to start “\ServerReboot” task for user “DOMAIN\user”. Additional Data: Error Value: 2147943645.

Solution

This error occurs when the user which the task is run under only has permission to run it when logged in.

To allow the task to run when the user is logged on or not, select Run whether user is logged on or not, on the General Tab in the Task Properties:
Task-Scheduler-Failed-2147943645_002

Moving tempdb file location for SQL Server 2008 R2

Problem

You’ve ran out of disk space on the drive where the tempdb files are located.

Solution

You need to move the tempdb files to a new location with sufficient disk space.

  1. Execute the following query:
    USE master; GO
    ALTER DATABASE tempdb
    MODIFY FILE (NAME = tempdev, FILENAME = '[new_path]\tempdb.mdf');
    GO
    ALTER DATABASE tempdb
    MODIFY FILE (NAME = templog, FILENAME = '[new_path]\templog.ldf');
    GO
  2. Stop and restart the instance of SQL Server.
  3. Once the service has been restarted, verify the changes using this query:
    sp_helpdb tempdb

Reference

Useful Perfmon Counters for SQL Server

I recently came across a useful poster showing Perfmon Counters for SQL Server.

You can download the PDF file here: SQLServer-Perfmonance-Poster

Setting up NTP for Server 2000 DC

Problem

You need to setup NTP on a Windows 2000 Server, then resync other servers (2000 and 2003 servers) to that one.

Solution

  1. First, query the current settings:
    net time /querysntp
  2. Set the NTP source server:
    net time /setsntp:uk.pool.ntp.org
  3. Stop and Start the Windows Time service:
    net stop w32time && net start w32time
  4. Force a resync on Win 2000 servers:
    w32tm -s
  5. Force a resync on Win 2003 servers:
    w32tm /resync

Source

Data Deduplication in Server 2012

Just read this great post on Data Deduplication in Server 2012: http://blogs.technet.com/b/keithmayer/archive/2012/12/12/step-by-step-reduce-storage-costs-with-data-deduplication-in-windows-server-2012.aspx#.UNRb3G_Zbzg

The post details that “enterprise organizations report that as much as 60% of their annual capital IT budget is related to storage hardware”, then goes on to explain data deduplication, and how to enable this feature in Server 2012.

Once the role is enabled, you can run DDPEVAL.exe, which will estimate the amount of disk space that can potentially be reclaimed by moving that data to a Windows Server 2012 NTFS volume with Data Deduplication enabled.

Here’s an excerpt:

When I’ve executed this against various shared folders on my servers, I’ve seen it compute anywhere between 30% – 80% estimated disk space reclamation, depending on the level of duplication on a volume and staleness of data.  Wouldn’t it be great to have 30% or more of your storage budget returned next year to spend on other projects?  Results may vary volume to volume, so I’d be very interested in hearing about your results!

Setting Up Windows Service Accounts for SQL Server

A useful link explaining the permissions for built-in system accounts and recommended usage for SQL Server 2008: http://technet.microsoft.com/en-us/library/ms143504(v=sql.100).aspx

More recent information on Windows Service Account and Permissions for SQL Server 2012 can be found here: http://msdn.microsoft.com/en-us/library/ms143504.aspx