Skip to content

Posts from the ‘SQL Server’ Category

SQL Server database restarting every couple of minutes


You may face an issue when your database is just restarting every couple of minutes and you can see check DB is running at same frequency under same spid, when you look into the SQL Server error log. But users are able to connect to database without any issues.

Below is the error message that you will find in SQL Server error log stating that database is starting:

Date                         6/6/2013 10:10:43 AM

Log                            SQL Server (Current – 6/6/2013 10:10:00 AM)

Source                     spid69


Starting up database ‘WW_Testing’.

Below is the error message that you will find in SQL Server error log stating that checkdb is running on this database:

Date                         6/6/2013 10:10:43 AM

Log                            SQL Server (Current – 6/6/2013 10:10:00 AM)

Source                     spid69


CHECKDB for database ‘WW_Testing’ finished without errors on 2013-06-01 11:00:24.160 (local time). This is an informational message only; no user action is required.


Regarding database restart, this will happen because you have set auto close database setting to enabled. So, your database is closed as soon as the last connection to this database is closed, but DB again restarts as soon as a new request to connect to database comes to SQL Server instance.

You can run below query to find if it is enabled or not. If output is 1 then its enabled If 0 then its disabled.

select is_auto_close_on from sys.databases

where name='DBNAME'

Now regarding checkDB running at same frequency, This is not a issue. SQL Server always performs checkDB whenever any database is started. This is to make sure a consistent copy of database is available before coming online. You will notice that this message comes every time after the Starting database message.


Only thing you need to do is to disable database auto close parameter by running below query in master database or by changing that by going to SSMS –> Databases –> DBNAME –> Right Click –> Properties –> Options –> Auto Close and set it to FALSE.

USE [master]




Script to list out all the SQL Server logins

Script to list out all the SQL Server logins along with its properties. The output of this script will be a create login script which can be run on the target machine where all these logins are to be migrated. You will see their are two selct queries in this script. First select query is to pull out all the SQL authenticated logins and second script will pull out all the Windows authenticated logins.

SELECT 'CREATE LOGIN ' + QUOTENAME(name) + ' WITH PASSWORD=' + sys.fn_varbintohexstr(password_hash) + ' HASHED, SID=' + sys.fn_varbintohexstr(sid) + ', ' + 'DEFAULT_DATABASE='+ QUOTENAME(COALESCE(default_database_name, 'master')) + ', DEFAULT_LANGUAGE=' + QUOTENAME(COALESCE(default_language_name, 'us_english')) + ', CHECK_EXPIRATION=' + CASE is_expiration_checked WHEN 1 THEN 'ON' ELSE 'OFF' END + ', CHECK_POLICY=' + CASE is_policy_checked WHEN 1 THEN 'ON' ELSE 'OFF' END as 'SQL Server Logins' FROM sys.sql_logins WHERE name not like 'sa' UNION ALL SELECT 'CREATE LOGIN ' + QUOTENAME(name) + ' FROM WINDOWS WITH ' + 'DEFAULT_DATABASE='+ QUOTENAME(COALESCE(default_database_name, 'master')) + ', DEFAULT_LANGUAGE=' + QUOTENAME(COALESCE(default_language_name, 'us_english')) as 'SQL Server Logins' FROM sys.server_principals WHERE type IN ('U','G') 

How to modify PSSDiag to run on different server?

If you already have a PSSDiag.exe provided by Microsoft and for some reason you have to run the same PSSdiag to collect same information in different server or database instance then you can do it easily just by making coule of chnages in PSSDiag.xml file.

NOTE:- When you run PSSDiag.exe, it will extract all the required files and one of that will be PSSDiag.xml

Steps to do:
1) Open PssDiag.xml in notepad.

2) Update Machine name. This will be server where your database instance is installed.
<Machine name=””>

If you are planning to run PssDiag by copying all files to srever and run from there, then you can just put “.” also. Dot means local serevr and should run fine.

3) Update database instance name.For named instance:
<Instance name=”SQL2008″ windowsauth=”true” ssver=”10″ user=””>

For default instance:
<Instance name=”MSSQL” windowsauth=”true” ssver=”10″ user=””>

4) Save the file and then pssdiag.

PSSDiag is created based on OS version, 32/64 bit machine, SQL Server version and database instance name. SO, above changes will work fine only if you are editting PSSDiag.xml file which was originally created for same OS version and 32/64bit machine.
For different SQL Server version and instance name, the above changes will work fine.

Detailed overview of PSSDiag

What is PSSDiag?

PSSDIAG is a general purpose diagnostic collection utility that Microsoft Product Support Services uses to collect various logs and data files. PSSDIAG can natively collect Performance Monitor logs, SQL Profiler traces, SQL Server blocking script output, Windows Event Logs, and SQLDIAG output. More info at

How to run PSSDiag?

Once you have fot PSSDiag.exe from Microsoft you may have to perform below steps to run PSSDiag.
1. Copy PSSDiag to E:\PSSDiag (You can copy to any drive which has sufficient space. In this example we will copy to E:\PSSDiag folder)
2. Open command prompt and go to E:\PSSDiag
3. Type PSSDiag.exe and hit enter. This will extract all the required files to E:\PSSdiag
4. Now type pssdiag and hit enter. This will start pssdiag on your server. It takes couple of minutes to initilize this service.

You service will be started when you get prompt like below (mosty in bold green color):
2013/02/02 11:10:12.80 PSSDIAG Collection started. Press Ctrl+C to stop.

5. Now to stop pssdiag just press Ctrl+C
6. Output of PSSDIag will be in Output folder at E:\PSSDiag. This utility will automatically create this folder if it does not exist and will overwrite if old output exists.

NOTE: If for some reason you are not able to access cmd or session is lost and you have to stop the PSSDIiag then just go to Output folder and create sqldiag.stop file from OS and PSSDiag will stop.

Now, the above step will work fine if you want to run pssdiag for small time frame. What to do if you have to run it for 12 hours. In this case you have to create a service for pssdiag and run from service.

How to create PSSDIag as service?

1. Run pssdiag /R after step 3 above.
2. Go to services.msc and you will see new service created as SQLDiag
3. This service will run under local system account by default. If BuiltInAdmin account is disabled then you have to change the account to some different account which has admin access on server as well as SQL Server instance. Best is to use the account under which your SQL Server service is running.
4. Right click on service and click Start to start PSSDiag
5. To stop, right click and hit Stop to stop PSSDiag

How to uninstall PSSDiag service?

Just run pssdiag /U and the service will be removed.

NOTE: Run “PSSDIAG /?” in command line to check all possible parameters that PSSDiag supports and can be used to run PSSDIag from command prompt.

How to change SMTP server in SQL Server database mail?

We may come up with a issue when old SMTP (Simple Mail Transfer Protocol) server used by database mail is either retired, replaced, not working and the only option we have is to change the SMTP server with some new server.

Steps to follow:

  • Connect to SQL Server Instance and navigate to Management à Database Mail à Right click à Configure Database Mail
  • Database Configuration Wizard will open. Click Next
  • In this windows select Manage Database Mail accounts and profiles, and then click Next
  • On this screen select View, change, or delete an existing account, and then click Next 
  • On this window change the SMTP server name under the field Server Name. You may also have to change Port number if SMTP server is not using the default port number i.e. Port Number 25
  • Next screen will be a summary of changes being made. Review the changes and click Finish to make changes

More Helpful information:

How about if you get a request to find all the database servers where old SMTP server is being used and replaces it with new server.

Here is a query that will help you to find the list of SMTP servers being used by database mail in a specific instance.

 SELECT distinct servername, @@SERVERNAME FROM msdb.dbo.sysmail_server