Search

Monday, July 24, 2017

An instance with the same name is already installed on this computer. To proceed with SQL Server setup, provide a unique instance name.

You may get below error while installing SQL Server.

An instance with the same name is already installed on this computer. To proceed with SQL Server setup, provide a unique instance name.

The main reason of above error is:

The named Instance, you are trying to install is already present.
The existing instance of SQL Server 2008 is a unique named instance. However, you try to install SQL Server 2005 as the default instance.
The existing instance of SQL Server 2008 is a named instance, and you use the same name when you try to install SQL Server 2005 as a named instance.

Follow below steps to solve the error (Suppose you want to create instance name SQLExpress:
Click Start menu, select Run and type regedit
Navigate to
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\
      Find “MSSQL$SQLExpress” , and delete
Go to HKEY_LOCAL_MACHINE\Software\Microsoft\Microsoft SQL Server
     Remove "SQLExpress" from the REG_MULTI_SZ value named InstalledInstance
     Delete the subhive named MSSQL.1
     Delete the subhive named SQLExpress
Go to HKEY_LOCAL_MACHINE\Software\Microsoft\Microsoft SQL Server\Instance Names\SQL
    Delete the value named  "SQLExpress"
Go to SQL Server installation drive Delete the folder %ProgramFiles%\Microsoft SQL Server\MSSQL.1
Restart the PC.

Use either Windows installer cleanup utility to manually remove all traces of MSSQL in your PC.

Re-run SQL installation

Alternatively, you can try installing SQL Server with different instance name.

Monday, April 17, 2017

A non recoverable I/O error occurred on file while taking backup.

You may get this error while taking backup of databse. 
The reason for this error is insufficient disk space.
The solution is either free up some space or change the backup folder.

Friday, December 2, 2016

The media family on device '' is incorrectly formed. SQL Server cannot process this media family. RESTORE FILELIST is terminating abnormally.

Error:

The media family on device ‘<FILENAME.BAK>’ is incorrectly formed. SQL Server cannot process this media family. RESTORE FILELIST is terminating abnormally.

Solution:

Ensure that backup file is good and copied properly.
You can not restore higher version databse Backup in lower version SQL Server.

Friday, October 21, 2016

Error occurred during installation: Error 1618 installing Microsoft SQL Server setup Support files.

You may get below error during SQL server installation:

Error occurred during installation: Error 1618 installing Microsoft SQL Server setup Support files.

Follow below steps to solve the error:

  1. Restart The system and try installing.
  2. Start - Run - Type: gpedit.msc - OK - Navigate to

Computer Configuration\Windows Settings\Security Settings\Local Policies\User Rights Assignment\Debug programs
Add administrator user.

Monday, May 30, 2016

Login failed for user ‘domain\username’. Reason: Server is in single user mode. Only one administrator can connect at this time.

You may get below error some time after improper shutdown of system.

Login failed for user ‘domain\username’. Reason: Server is in single user mode. Only one administrator can connect at this time.

Restart SQL server and Browser and problem will be solved.

Thursday, February 18, 2016

Query to get IP address of SQL Server

Use below query to get IP address of SQL Server:

DECLARE @IP varchar(40)
DECLARE @IPLine varchar(200)
DECLARE @Pos int

SET NoCount ON
SET @IP = NULL

Create Table #Temp (IPLine VarChar(200))
INSERT #temp EXEC master..xp_cmdshell 'IPconfig'

SELECT TOP 1 @IPLine = IPLine FROM #Temp
WHERE Upper (IPLine) LIKE '%IP ADDRESS%' OR Upper (IPLine) LIKE '%IPV4 ADDRESS%' 
    IF (ISNULL (@IPLine,'***') != '***')
      BEGIN 
       SET @Pos = CharIndex (':',@IPLine,1);
       SET @IP = LTrim(RTrim(SubString (@IPLine , @Pos + 1 ,len (@IPLine) - @Pos)))
      END 
PRINT @IP
DROP TABLE #temp
SET NoCount OFF

If you get below error after executing above query:

Msg 15281, Level 16, State 1, Procedure xp_cmdshell, Line 1
SQL Server blocked access to procedure 'sys.xp_cmdshell' of component 'xp_cmdshell' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'xp_cmdshell' by using sp_configure. For more information about enabling 'xp_cmdshell', see "Surface Area Configuration" in SQL Server Books Online.

Than you had to enable xp_cmdshell in surface area configuration. and than rerun the above query.

Monday, February 8, 2016

How to show backup or restore progress to user in a progressbar?

You can show backup or restore progress to user in a progress bar if you had installed 

sp_who2k5 

into your master database. You have to run the below command:

sp_who2k5 1, 1

The result will include all active transaction. Search the backup in the requestCommand field. The aptly named percentComplete field will give you the progress of the backup. 

Monday, February 1, 2016

The SQL Server system configuration checker cannot be executed due to WMI configuration on the machine.

Last week I got below error in clients system:

The SQL Server system configuration checker cannot be executed due to WMI configuration on the machine. Error 2147749896

The main cause of the problem are:

Unfinished SQL Server components may be present.
Components or files related to WMI service might be unregistered or missing.
Microsoft Data Access Components may not be installed.
The problem was that the WMI repository is corrupted. Reinstall the WMI.

Solution:
Check the version of MDAC you have installed. SQL Server will require MDAC 2.8 or higher. To check MDAC:
Click Start / Run. Type regedit. Click OK.
Navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\DataAccess
Note the Registry Key for Version. If less than 2.8.xxxx,
download and install the latest MDAC 2.8 version.

Monday, January 11, 2016

Error: 64, connection was successfully established with the server, but then an error occurred during the pre-login handshake.

I had got below error in my friend's system:

A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 0 – The specified network name is no longer available.) (Microsoft SQL Server, Error: 64)

I googled this error and got mixed results and solutions but none solved my problem.


After some more googling I found below solution that worked for me.
The solution is:
Go to the MSSQL Configuration Manager and expand the SQL Network Configuration and click on the PROTOCOLS node. Right click on TCP/IP and open up the PROPERTIES panel and Select the IP ADDRESS tab.
Check the IP ADDRESS field's value are correct and match the system it is running on.
Restart the service, and the problem is solved.
Make sure you fill in the TCP PORT, even if you are using the default 1433.

Monday, January 4, 2016

Error occurred during database creation

Sometime when you create a new database by using CREATE Database statement in SSMS (SQL Server Management Studio), you may got below error message and you are not able to create Database:

Server: Msg 5105, Level 16, State 2, Line 1
Device activation error. The physical file name '' may be incorrect.

Server: Msg 1802, Level 16, State 1, Line 1
CREATE DATABASE failed. Some file names listed could not be created. Check previous errors. 

The main reason of above error is path of folder store in the registry values does not exist. When the path of folder is incorrect then MS SQL server throws above error messages.

You can fix the error by using SSMS. SSMS is able to set the default directory value for Data and log Files. Follow below steps to change the default value: 


  • Start SQL server Management Studio.
  • In Management Studio, right click on your instance and select properties
  • In properties, click on the database setting option.
  • Now go to the new database default location section
  • Correct folder path from default directory box and default log directory box
  • Press OK
  • Stop the instance of MS SQL database
  • Restart the instance of MS SQL server database.

Monday, November 2, 2015

List database objects modified in the last ‘X’ days

Use below query to get the list of databases modified in last 'X' days:

USE <database_Name>; 
GO 
SELECT Name AS object_Name,  
  Create_Date, Modify_Date, 
  Type_Desc,
  SCHEMA_Name(Schema_ID) AS Schema_Name 
FROM sys.Objects 
WHERE Modify_Date > GETDate() - <X_Days> 
ORDER BY Modify_Date; 
GO 

Notes: Replace <database_Name> with Database Name and <X_Days>  with No of days.

Monday, September 14, 2015

Weekend count between two dates

Use below query to find the weekend count between two dates:

DECLARE @DateFrom DateTime, @DateTo DateTime, @Total int, @Number int, @Counter int
SELECT @DateTo = GetDate(), @DateFrom = GetDate() - 22, @Total = DateDiff(dd, @DateFrom, @DateTo), @Number = 1, @Counter = 0
WHILE (@Number <= @Total)
BEGIN
IF DatePart(dw, @DateFrom) = 1 OR DatePart(dw, @DateFrom) = 7
BEGIN
SET @Counter = @Counter +1
END
SET @DateFrom = @DateFrom+1
SET @Number = @Number + 1
END
PRINT @Counter

Monday, August 24, 2015

Find LOB Columns Script

Sometime you want to identify the tables which could not reindex online. For this you had to scan all tables in SQL Server database and list the columns which are large objects (VarChar(MAX), NVarChar(MAX), XML, VarBinary, Text, NText, Image).
There are various method to get above information:
Method 1
SELECT * FROM Information_Schema.Columns
WHERE Table_Name IN 
    (SELECT Table_Name 
     FROM Information_Schema.Tables 
     WHERE Table_Type = 'Base Table')
AND DATA_TYPE IN ('VarChar', 'NVarChar', 'VarBinary', 'Text', 'NText', 'Image', 'XML')
AND Character_Maximum_Length = -1
ORDER BY Table_Name

Method 2
SELECT 
    C.Object_ID, 
    Object_Name(C.Object_ID) AS [Object Name], 
    C.Name AS [Column Name], 
    T.Name AS [Column Type]
FROM Sys.Columns C
INNER JOIN Sys.Types T ON C.System_Type_ID = T.System_Type_ID 
WHERE C.Object_ID IN (SELECT Object_ID FROM Sys.Objects WHERE Type_Desc = 'User_Table')
AND C.max_length = -1
AND T.Name IN ('VarChar', 'NVarChar', 'VarBinary', 'Text', 'NText', 'Image', 'XML')

Monday, August 17, 2015

Unable to modify table.

I was trying to modify a table of approx 5 million records setting a field on the table to not allow null values. However, while saving changes in table, I got below error:

'Account ' table
- Unable to modify table. 
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.


After that I click ok button and I got below error:

User cancelled out of save dialog.

This error is coming because table designer have a default timeout value of 30 secs. And as I am saving a table with huge records, it is taking time more than 30 secs, so above error coming.

So the solution is to increase the timeout value of designer, (the maximum value for timeout is 65535).
Click on tools menu - Options - Expand designers. Now here change the timeout value in "Table and Database designers" on the right side.

Monday, July 20, 2015

Record Retrieval Error Connection Read

You may receive below error while running third party application with backend SQL Server.

Record Retrieval Error
Error: (Connection Read(recv()).(01000)) attempting to access a record from the MERCAN file. Returning to previous window.


The application is showing this error because it lost the network connectivity with the SQL Server instance for a short period of time.

So, restart the application once the network issue is solved.

Monday, June 29, 2015

Attach Database Failed

Sometime you may get below error while attaching a database:

Attach database failed for Server 'SERVERNAME\SQLEXPRESS'. (Microsoft.SqlServer.Express.Smo)

Additional information:
An exception occurred while executing a Transact-SQL statement or batch.
(Microsoft.SqlServer.Express.ConnectionInfo)

Unable to open the physical file "filename.mdf". Operating system error 5: "5(error not found)".(Microsoft SQL Server, Error: 5120)


To solve above error, make sure that the SQL Server Service account has modify permissions over the physical file on the hard drive that you are trying to attach to a SQL Server instance, and modify permissions also over the folder that contains the file.

Monday, June 22, 2015

Query to get details of permissions on Database objects

Use below query to get details of permissions on Database objects

SELECT ulogin.name AS [User Name],
CASE princ.type WHEN 'U' THEN 'Windows User' WHEN 'G' THEN 'Windows Group' WHEN 'S' THEN 'SQL User' END AS [User Type],
princ.name AS [Database User Name], perm.permission_name AS [Permission Type], perm.state_desc AS [Permission State],
CASE perm.class WHEN 1 THEN obj.type_desc ELSE perm.[class_desc] END AS [Object Type],
CASE perm.class WHEN 1 THEN OBJECT_NAME(perm.major_id) WHEN 3 THEN schem.[name] WHEN 4 THEN imp.[name] END AS [Object Name],
col.name AS [Column Name]
FROM sys.database_principals princ LEFT JOIN sys.server_principals ulogin on princ.sid = ulogin.sid LEFT JOIN sys.database_permissions perm ON perm.grantee_principal_id = princ.principal_id  LEFT JOIN sys.database_principals imp ON imp.principal_id = perm.major_id LEFT JOIN sys.columns col ON col.object_id = perm.major_id AND col.column_id = perm.minor_id  LEFT JOIN sys.schemas schem ON schem.schema_id = perm.major_id LEFT JOIN sys.objects obj ON perm.major_id = obj.object_id
WHERE princ.[type] IN ('S','U','G') AND princ.[name] NOT IN ('sys', 'INFORMATION_SCHEMA')

Monday, June 15, 2015

Log backup to replace maintenance plan

Use below script to restore maintenance plan from log backup:

USE [Master]
GO
DECLARE @BackupExtention nVarChar(4); SET @BackupExtention = '.trn'
DECLARE @DB nVarChar(128); SET @DB = ''
DECLARE @BackupDir nVarChar(138);

--loop through each databASe in full recovery mode
WHILE @DB < ( SELECT MAX(Name) FROM sysDatabases WHERE DATABASEPROPERTYEX(Name,'RECOVERY') = 'FULL' )
BEGIN
SELECT @DB = MIN (Name)  FROM sysDatabases WHERE DATABASEPROPERTYEX(Name,'RECOVERY') = 'FULL' AND Name > @DB
DECLARE @DatabaseName nVarChar(128); SET @DatabaseName = @DB --SET @DatabaseName = 'TFSWarehouse'
DECLARE @DateTimestamp nVarChar(14); SET @DateTimestamp = '_' + CONVERT(VarChar, GetDate(), 112) + '_' + replace(CONVERT(VarChar, GetDate(), 108),':','')
DECLARE @RemoteBackupPath nVarChar(260);
SET @BackupDir = N'D:\Backup\' + @DatabaseName
SET @RemoteBackupPath = @BackupDir + N'\' + @DatabaseName + @DateTimestamp + @BackupExtention
DECLARE @BackupDevice nVarChar(128); SET @BackupDevice = N'local_' + @DatabaseName + @BackupExtention
--SELECT @DatabaseName, @BackupDevice, @RemoteBackupPath
--drop AND recreate the backup device
IF Exists(SELECT NULL FROM sys.Backup_Devices WHERE Name = @BackupDevice)
EXEC Master..sp_DropDevice @LogicalName = @BackupDevice
EXEC Master.dbo.sp_AddumpDevice @DevType = N'disk', @LogicalName = @BackupDevice, @PhysicalName = @RemoteBackupPath
--create the subdirectory if not already preset
EXECUTE Master.dbo.xp_Create_SubDir @BackupDir
--execute the backup
BACKUP LOG @DatabaseName TO  DISK = @RemoteBackupPath WITH NOFORMAT, NOINIT,  Name = @BackupDevice, SKIP, REWIND, NOUNLOAD,  STATS = 10
END
GO

Monday, June 1, 2015

Unable to open DTS package in SQL 2008 Management Studio

Sometime when we try to import a SQL Server 2000 DTS package into SQL Server 2008 R2 using SSMS, the following error appears:

Managing DTS packages in SQL Server Management Studio requires the SQL Server 2000 Data Transformation Services (DTS) runtime. To install the DTS runtime, on your SQL Server 2008 R2 installation media, locate and run the Windows Installer package for SQL Server 2005 Backward Compatibility (SQLServer2005_BC*.msi). You can also download the DTS runtime from the SQL Server Feature Pack page on the Microsoft Download Center. (Microsoft.SqlServer.DtsObjectExplorerUI)

As suggested, the “Microsoft SQL Server 2005 Backward compatibility” package must be installed. It can be found on this location: http://www.microsoft.com/en-us/download/details.aspx?id=3522

After the installation of “Microsoft SQL Server 2005 Backward compatibility” package the DTS package is imported successfully. Now when we try to open the DTS package, the following error appears:

SQL Server 2000 DTS Designer components are required to edit DTS packages. Install the special Web download, “SQL Server 2000 DTS Designer Components” to use this feature. (Microsoft.SqlServer.DtsObjectExplorerUI)

To solve this error the “Sql Server 2000 DTS Designer Components” package must be installed. It can be found on this location: http://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=11988

After the installation try to open again the DTS package in SSMS.   

SQL Server 2000 DTS Designer components are required to edit DTS packages. Install the special Web download, “SQL Server 2000 DTS Designer Components” to use this feature. (Microsoft.SqlServer.DtsObjectExplorerUI)

If the same error appears, copy the DLL and RLL files as described in below Microsoft link: http://msdn.microsoft.com/en-us/library/ms143755.aspx

To ensure that the DTS designer can be used in SQL Server Management Studio

1. Copy the files, SEMSFC.DLL, SQLGUI.DLL, and SQLSVC.DLL, from the %ProgramFiles%\Microsoft SQL Server\80\Tools\Binn folder to the %ProgramFiles%\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE folder.

2. Copy the files, SEMSFC.RLL, SQLGUI.RLL, and SQLSVC.RLL, from the %ProgramFiles%\Microsoft SQL Server\80\Tools\Binn\Resources\%lang_id% folder to the %ProgramFiles%\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Resources\%lang_id% folder.

For example, for U.S. English, the lang_id subfolder will be "1033".
To ensure that the DTS designer can be used in Business Intelligence Development Studio

1. Copy the files, SEMSFC.DLL, SQLGUI.DLL, and SQLSVC.DLL, from the %ProgramFiles%\Microsoft SQL Server\80\Tools\Binn folder to the %ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE folder.

2. Copy the files, SEMSFC.RLL, SQLGUI.RLL, and SQLSVC.RLL, from the %ProgramFiles%\Microsoft SQL Server\80\Tools\Binn\Resources folder to the %ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE\Resources\%lang_id% folder. For example, for U.S. English, the lang_id subfolder will be "1033".

Monday, May 11, 2015

List Table with Identity Column

You can use below queries to get the list of all the tables with Identity column:

SELECT OBJECT_NAME(ID) AS [Table], Name AS [Column]
FROM syscolumns WHERE COLUMNPROPERTY(ID, Name, 'IsIdentity') = 1

Or use can use below query also

SELECT OBJECT_NAME(ID) AS [Table], Name AS [Column]
FROM syscolumns WHERE STATUS = 0x80

You can use blow query to check whether the table has Identity column:

SELECT Name AS [Table], OBJECTPROPERTY(ID, 'TableHasIdentity') AS [Has_Identity]
FROM SysObjects WHERE xType = 'U'