Monthly Archives: April 2009

Linked Server Problem – Windows 2003 SP1. (Setting MSDTC Security Configuration)

In one of our server running Windows 2003 & SQL Server 2000 our system administrators has applied the service pack 1 and they have completed successfully. The next day night all the SQL jobs in another server (Windows 2000 & SQL Server 2000) which is configured to link the Win2k3 server has been failed with the error message below.

Executed as user: mydomain\sqlaccount. The operation could not be performed because the OLE DB provider ‘SQLOLEDB’ was unable to begin a distributed transaction. [SQLSTATE 42000] (Error 7391)   [SQLSTATE 01000] (Error 7312)  OLE DB error trace [OLE/DB Provider 'SQLOLEDB' ITransactionJoin::JoinTransaction returned 0x8004d00a]. [SQLSTATE 01000] (Error 7300).  The step failed.

Read more »

VN:F [1.9.13_1145]
Rating: 0.0/5 (0 votes cast)
VN:F [1.9.13_1145]
Rating: 0 (from 0 votes)

Startup procedure to check SQL Server status when restarted

I’ve written a startup procedure to check SQL Server status when the SQL Server gets restarted. Most of the time as a DBA when a Server gets rebooted or SQL Services is restarted we need to make sure everything is fine in SQL server to make sure SQL server is running healthy. Some companies will have budget to buy a monitoring tool, so that all these things will be taken care by that tool. This small procedure will help the DBA’s to know the status of SQL Server in HTML format through mail when it’s restarted.

Applies to:

  • SQL Server 2005
  • SQL Server 2008

Pre-Requisites

  • Xp_cmdshell procedure should be in enabled state
  • A database mail profile should be configured as default profile (else you need to provide this profile information inside the procedure)
    Script
    This script will monitor the below parameters in SQL Server.
  • SQL Server Uptime
  • SQL Server Service Status
  • SQL Server Agent Status
  • Database(s) status
  • Authentication mode
/*
Procedure Name : serverstartup
Written By : Vidhya Sagar
www.sql-articles.com
*/
USE master
GO
CREATE PROC serverstartup
AS
SET NOCOUNT ON
IF EXISTS(SELECT 1 FROM tempdb..sysobjects where name ='##sqlservice')
DROP TABLE ##sqlservice
CREATE TABLE ##sqlservice (details VARCHAR(100))
IF EXISTS(SELECT 1 FROM tempdb..sysobjects where name ='##agentservice')
DROP TABLE ##agentservice
CREATE TABLE ##agentservice (details VARCHAR(100))
WAITFOR DELAY '00:02'
DECLARE @sname VARCHAR(100), @starttime VARCHAR(30)
DECLARE @authmode VARCHAR(25), @subject VARCHAR(250)
DECLARE @insname VARCHAR(50),@agentname VARCHAR(50)
DECLARE @sqlstatus VARCHAR(100), @agentstatus VARCHAR(100)
DECLARE @dbstatus VARCHAR(100), @dbdetail VARCHAR(2000)
DECLARE @sctsql VARCHAR(200), @HTML VARCHAR(8000)
SELECT @sname = @@SERVERNAME
SELECT @authmode=case SERVERPROPERTY('IsIntegratedSecurityOnly') when 1 then 'Windows' else 'Mixed' end
SELECT @starttime=CONVERT(VARCHAR(30),create_date,109) from sys.databases where database_id=2
IF (serverproperty('InstanceName')) IS NOT NULL
BEGIN
SET @insname='mssql$'+CONVERT(VARCHAR(40),serverproperty('InstanceName'))
SET @agentname='sqlagent$'+CONVERT(VARCHAR(40),serverproperty('InstanceName'))
END
ELSE
BEGIN
SET @insname='mssqlserver'
SET @agentname='sqlserveragent'
END
SELECT @sctsql='EXEC master.dbo.xp_cmdshell ''sc query '+@insname+' | FIND "STATE"'''
INSERT ##sqlservice
EXEC (@sctsql)
SELECT @sctsql='EXEC master.dbo.xp_cmdshell ''sc query '+@agentname+' | FIND "STATE"'''
INSERT ##agentservice
EXEC (@sctsql)
IF EXISTS(SELECT 1 FROM ##sqlservice WHERE details LIKE '%RUNNING%')
SET @sqlstatus = 'Running'
ELSE
SET @sqlstatus = '<font color="red">Not Running</font>'
IF EXISTS(SELECT 1 FROM ##agentservice WHERE details LIKE '%RUNNING%')
SET @agentstatus = 'Running'
ELSE
SET @agentstatus = '<font color="red">Not Running</font>'
IF EXISTS (SELECT 1 FROM sys.databases WHERE state_desc<>'ONLINE')
BEGIN
SET @dbstatus= '<font color="red">Some of the database(s) are offline</font>'
SELECT @dbdetail = '<table border="1"><tr><th>Database Name</th><th>Database Status</th></tr><tr>'
SELECT @dbdetail = @dbdetail + '<td  align="Center">' + name + '</td><td  align="Center">'+state_desc+'</td></tr></table>' FROM sys.databases WHERE state_desc<>'ONLINE'
END
ELSE
BEGIN
SET @dbdetail = ''
SET @dbstatus='All databases are online'
END
SET @subject=@sname+' : SQL Server is restarted. Please Check'
SET @HTML='<h3>'+@sname+'</h3><br>'+'<table border="1"><tr><th>SQL Server Startup time</th><th>SQL Server Service</th><th>SQL Agent Service</th> <th>Database(s) Status</th><th>Authentication Mode</th></tr><tr><td align="Center">'+
@starttime+'</td><td align="Center">'+@sqlstatus+'</td><td align="Center">'+@agentstatus+'</td><td align="Center">'+@dbstatus+'</td><td align="Center">'+@authmode+'</td></tr></table><br><br>'+@dbdetail
EXEC msdb.dbo.sp_send_dbmail
@recipients ='kvs1983@indiamvps.net',
@subject=@subject,
@body =@HTML,
@body_format ='HTML'
GO
---Enabling startup parameter for that procedure
EXEC sp_procoption 'serverstartup','startup',True
GO

Download Script Here

In the script above there are two parameters that need to be taken care by the implementer.

  • WAITFOR – I’ve used this command since this is the time for the database to get into steady state i.e. roll back and roll forward time. If the database is in huge size then the roll back or roll forward will take some time, you need to adjust this value based on the time its taking. By default I’ve set this value to 2 min.
  • Mail Recipients – You need to provide the email address to whom the alert mail need to be delivered. In the script above I’ve used my hotmail ID. Please change this to your mail ID. If you don’t have a default mail profile, then use @profile_name parameter in the mail procedure to use the correct mail profile.

Testing

Let’s test the script developed. Since the script is marked for startup when ever SQL Server is restarted this procedure will run and provide the health check status for SQL Server to the mail recipients given in the script.

  • When Everything is normal and running fine.

serverstartup-1

  • In this case I’ve stopped SQL Agent service, lets check the alert mail. You can find SQL Agent status as not running.

serverstartup-2

  • Now lets make a database to emergency mode. I’ve created a new database named EMERGENCY_TEST and made it to emergency mode. From the mail below you can check that you can get the db details too.

serverstartup-3

I’m sharing this procedure since some of the DBA’s might use this procedure to simplify their process.

Your comments are suggestions are always welcomed to improve me better. You can either post your queries @ Forums sections else mail me.

VN:F [1.9.13_1145]
Rating: 3.8/5 (4 votes cast)
VN:F [1.9.13_1145]
Rating: +2 (from 2 votes)

Resource Database – 5th System database

In this article we are going to take a look at the 5th system databases available right from SQL Server 2005. As everyone know till SQL Server 2000 there are four system database is available and they are master, model, msdb and tempdb databases. From SQL Server 2005 Microsoft has introduced a new system database to the database engine called Resource database (actual name for this database is mssqlsystemresource ) which is hidden to the users. Read more »

VN:F [1.9.13_1145]
Rating: 0.0/5 (0 votes cast)
VN:F [1.9.13_1145]
Rating: 0 (from 0 votes)

SQL Server 2008 Service Pack 1 (SP1) Released

Today Microsoft has released the final version of Service pack 1 for SQL Server 2008. You can download it from the  link below. Some of the new features are included in SQL Server 2008 service pack 1.

  • Slipstreaming is an installation method that integrates the base installation files for a program with its service packs and enables them to be installed in a single step. You can slipstream a SQL Server 2008 update and the original installation media so that original media and the update are installed at the same time. The update setup documentation available from the Download Center has the most recent description of the slipstream process. The update setup documentation is also available at MSDN.
  • You can uninstall SQL Server 2008 cumulative updates or service packs from Programs and Features in Control Panel. For more information, see “Overview of SQL Server Servicing Installation” in the update help file.
  • SQL Server 2008 Service Pack 1 provides a ClickOnce version of Report Builder 2.0. Report Builder is available for use in Reporting Services (SSRS) installed in native or SharePoint integrated mode. If SSRS is installed in SharePoint integrated mode, you need to install the add-in, Microsoft SQL Server 2008 Report Builder 2.0 ClickOnce for SharePoint, to make Report Builder 2.0 ClickOnce available from a SharePoint site. For more information, see the Report Builder 2.0 ClickOnce for SharePoint Readme.

Read more »

VN:F [1.9.13_1145]
Rating: 0.0/5 (0 votes cast)
VN:F [1.9.13_1145]
Rating: 0 (from 0 votes)

Creating Linked server to MYSQL from SQL Server

In this article we going to look into creating a heterogeneous linked server. i.e. We are going to create a linked server to MYSQL database server from SQL Server environment and then going to query data’s from MYSQL. First step in heterogeneous linked server is to create a ODBC connection to that RDBMS platform. For creating ODBC connection we need the ODBC drivers for that RDBMS platform. In this we need drivers for MYSQL, this is not included in windows you need to download it from MYSQL Website. Lets discuss on this step by step

Testing Environment

Windows Server 2008
SQL Server 2008
MySQL Version 5.0.51
MySQL ODBC Driver 5.1
MySQL DBName : sqlarticles

Read more »

VN:F [1.9.13_1145]
Rating: 4.8/5 (5 votes cast)
VN:F [1.9.13_1145]
Rating: +5 (from 7 votes)