Happy Republic Day
January 25, 2012 Leave a Comment

Articles on SQL Server and MySQL
January 18, 2012 1 Comment
Problem: If there are multiple SQL instances running on the same computer, it is difficult to identify the instance port number. You can use the below solution to find the instance specific port numbers.
Solution: You can check the list of port number used by the SQL Server instances using one of the below way.
Soln 1# Using SQL Server Configuration Manager
Soln 2#From Registry Values
SQL Server 2005
Type the regedit command in Run window and check the below registry values.HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL.#
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\ MSSQL.#\ MSSQLServer\ SuperSocketNetLib\TCP\IPAll
SQL Server 2008
Default instance
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQLServer\SuperSocketNetLib\TCP\IPAll
Named instance
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10.(InstanceName)\MSSQLServer\SuperSocketNetLib\TCP\IPAll
Soln 3# Error Log
Query the error log as below to get the port number.
EXEC xp_readerrorlog 0,1,”Server is listening on”,Null
Soln 4# Command Prompts
Execute the below command from the command prompt.
Netstat -abn
January 6, 2012 1 Comment
Lock Pages in Memory
You can prevent the Windows operating system from paging out the buffer pool memory of the SQL Server process by locking the memory that is allocated for the buffer pool in physical memory. You lock the memory by assigning the Lock pages in memory user right to the user account that is used as the startup account of the SQL Server service.
Model Database Whenever we create a new database, it will use model as template. Configure model DB for the Auto Shrink OFF, Auto Update/Create Statistics on
Maximum Worker Threads: Based on the load increase the maximum work thread.
Address Windowing Extensions (AWE) is an API that allows a 32-bit application to manipulate physical memory beyond 4 GB memory limit. The AWE mechanism technically is not necessary on 64-bit platform. It is, however, present there. Memory pages that are allocated through the AWE mechanism are referred as locked pages on the 64-bit platform.
On both 32-bit and 64-bit platforms, memory that is allocated through the AWE mechanism cannot be paged out. This can be beneficial to the application. (This is one of the reasons for using AWE mechanism on 64-bit platform.) This also affects the amount of RAM that is available to the system and to other applications, which might have detrimental effects. For this reason, in order to use AWE, the Lock Pages in Memory privilege must be granted for the account that runs SQL Server.
Please note:
.
December 31, 2011 1 Comment
Dear Readers,
Wish you all very happy and prosperous New Year 2012.
Thanks,
Jugal Shah
December 30, 2011 1 Comment
There are many scenarios where you have been alerted for the replication failure and you have to troubleshoot the issue. In this article I will guide you what should be your approach to get the detailed error message and transaction details in replication.
First check the replication monitor and click on the failed publisher. Next step is double click on the failed subscriber from All Subscriptions list.
Now next step is click on the error and check its description.
Error :
Command attempted:
if @@trancount > 0 rollback tran
(Transaction sequence number: 0x0000044100002D93000100000000, Command ID: 1)
From the above error message we have to identify which command is failed to execute on the subscriber.
To get the exact command, find out the distributer server and distribution database for the failed publisher.
Once you get the distribution database server, execute the below query against the distribution DB.
use distribution go SELECT * FROM msrepl_commands WHERE xact_seqno = 0x0000044100002D93000100000000 AND command_id = 1
We have to use the above details, to get the exact command using either SP_BROWSEREPLCMDS (If CLR is enabled) or you can cast the command column in msrepl_commands table.
We will check both the alternatives.
Using SP_BROWSEREPLCMDS
Please note CLR must be enabled for to use this procedure.
EXEC SP_BROWSEREPLCMDS @xact_seqno_start = '0x0000044100002D930001', @xact_seqno_end = '0x0000044100002D930001', @publisher_database_id = 1033, @article_id = 12, @command_id= 1
By casting command column in msrepl_commands table
Please note if you want to see the better output use the Result to Text as output in SSMS (CTRL + T)
SELECT CAST(SUBSTRING(command, 7, 8000) AS NVARCHAR(MAX)) FROM msrepl_commands WHERE xact_seqno = 0x0000044100002D930001 AND command_id = 1
Now you got the exact SQL Command. As a next step check the objects from both the publisher and the subscriber to see the violation of the keys or do the data comparisons etc.
December 27, 2011 1 Comment
Think of environment where multiple jobs are running at the same time and you want to monitor the current status of each job. One option is to use the job activity monitor.
And another way is you can use the below system stored procedures by running it against the MSDB database.
exec msdb..sp_get_composite_job_info
@execution_status=1
exec msdb.dbo.sp_help_job
@execution_status = 1
You can check the job execution status parameter values as below.
0 = Not idle or suspended
1 = Executing
2 = Waiting For Thread
3 = Between Retries
4 = Idle
5 = Suspended
6 = Waiting For Step To Finish
7 = Performing Completion Actions
December 21, 2011 1 Comment
Problem
Log shipping has been an option for creating a fail over server for SQL Server for quite some time. In this tip, we look at different ways that you can monitor the status of your log shipped databases.
http://www.mssqltips.com/sqlservertip/2553/different-ways-to-monitor-log-shipping-for-sql-server-databases/
December 20, 2011 Leave a Comment
Problem: There could be situation where you missed the database transaction log file(.LDF) and you have only data file (.MDF). You can attach the database using below solution.
Solution: In the below script I have created the database,dropped its log file and created the database with the .mdf file.
--created database with .mdf and .ldf file
CREATE DATABASE [singleFileDemo] ON PRIMARY
( NAME = N'singleFileDemo', FILENAME = N'L:\singleFileDemo.mdf' , SIZE = 2048KB , FILEGROWTH = 10240KB )
LOG ON
( NAME = N'singleFileDemo_log', FILENAME = N'F:\singleFileDemo_log.ldf' , SIZE = 1024KB , FILEGROWTH = 5120KB )
GO
--inserting data into database
use singleFileDemo
create table tb1 (name varchar(10))
--inserting records
insert into tb1 values('Jugal')
go 10;
--deleting the log file
--detaching the database file
USE [master]
GO
EXEC master.dbo.sp_detach_db @dbname = N'singleFileDemo'
GO
-- now next step is delete the file manually or you can do it from command prompt
EXEC xp_cmdshell 'del F:\singleFileDemo_log.ldf'
-- script to attach the database
USE [master]
GO
CREATE DATABASE [singleFileDemo] ON
( FILENAME = N'L:\singleFileDemo.mdf' )
FOR ATTACH
GO
When you will execute the CREATE DATABASE FOR Attach script you will get the below warning message.
File activation failure. The physical file name "F:\singleFileDemo_log.ldf" may be incorrect.
New log file 'F:\singleFileDemo_log.LDF' was created.
Once the database is ready execute the DBCC CHECKDB for any error.
December 13, 2011 1 Comment
Pathping is a Windows based command-line tool used to provide information about the path data takes to its destination, network latency and network loss at intermediate hops between a source and destination.
December 8, 2011 1 Comment
xp_msver returns information about the SQL Server version, actual build number of the server and information about the server environment.
You can also pass the parameter to get the specific information.

December 2, 2011 Leave a Comment
You can enable the database for replication using below script.
use master exec sp_replicationdboption @dbname = 'sqldbpool', @optname = 'publish', @value = 'true' go
If you have restore the database on test environment and you are getting the error that “Database is part of Replication”, you can clear/disable it by executing below query.
use master exec sp_replicationdboption @dbname = 'sqldbpool', @optname = 'publish', @value = 'false' go
November 25, 2011 Leave a Comment
ProblemIn this tip we look at the steps within SQL Server you need to follow if you change the physical server name for a standalone SQL Server.
Solution
http://www.mssqltips.com/sqlservertip/2525/steps-to-change-the-server-name-for-a-sql-server-machine/