Friday, April 23, 2010

Error while renaming database

Error

Unable to rename coltest_Org. (ObjectExplorer)
Rename failed for Database 'coltest'. (Microsoft.SqlServer.Smo)
An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)
------------------------------
The database could not be exclusively locked to perform the operation. (Microsoft SQL Server, Error: 5030)

Solution

Check if any other user is using the database or having lock on database object to be rename using following script

DECLARE @Database varchar(128)
Set @Database=''
SELECT DISTINCT SPID
FROM sys.syslockinfo L with(nolock)
INNER JOIN SYS.SYSPROCESSES P with(nolock) ON P.SPID=L.req_spid
WHERE L.rsc_indid=db_id(@Database)
OR P.dbid=db_id(@Database)


Kill the SPID's or wait for it to be completed if not running\suspended.
Then rename database.

Thursday, April 22, 2010

Collation issue when querying two tables on a join

Error




Cannot resolve the collation conflict between "SQL_Latin1_General_CP1_CI_AS" and
"SQL_Latin1_General_CP850_BIN" in the equal to operation.



Issue



Column collation setting for user_table\variable_table\temp_table for data
type char\text\varchar columns should be the same while comparison.


Fix




i.e.


DECLARE @DBList as table
( DatabaseID int, DatabaseName varchar(128) COLLATE SQL_Latin1_General_CP850_BIN not null)

Monday, April 5, 2010

Msg 62301, Level 18, State 1, Line 0

Error
Msg 62301, Level 18, State 1, Line 0
SQL Server has returned a failure message to LiteSpeed for SQL Server which has prevented the operation from succeeding.
The following message is not a LiteSpeed for SQL Server message. Please refer to SQL Server books online or Microsoft technical support for a solution:
RESTORE DATABASE is terminating abnormally.
The backup set holds a backup of a database other than the existing 'Testing' database.

Solution
You are restoring different database backup than the previously restored database.
Check\confirm database name and server name using following script
RESTORE DATABASE HEADERONLY FROM DISK=N'Database_Backup_File_Path'

Friday, April 2, 2010