Monday, December 17, 2012

Evaluation period has expired, SQL Server 2012

How to upgrade Evaluation edition or use Licence key to the SQL Server Services.


Run SQL Server 2012 Setup file as administrator and select maintenance link as shown below. 
Select Edition Upgrade; Edition Upgrade meaning you are actually Upgrading Evaluation edition to Enterprise edition by entering Licence key. Make sure you have Enterprise Edition KEY only other editions keys are not Accepted. 










And finally restart services and start the Management Studio.


Friday, November 30, 2012

Role Management Tool to Install .NET FrameWork 3.5


You get this error when Installing SQL Server 2012 Enterprise edition. 
Because SQL Server 2012 ships with .NET 4.0 Framework. 

And Windows 2008R2 already has 3.5 inbuilt you just need to enable the already existed feature within WINDOWS 2008R2 from server manager as shown below. 




 











Server Manager Enable .NET FrameWork 3.5.1 Feature. 
Right click on computer and select Manager and browse to Features as shown below. 

Once selected this feature and continue SQL Server 2012 Installation it will be go smooth. 


Thursday, October 4, 2012

Shrinking Database Log Files.

Often many get confused when the log grows and don't know what to do?

So here it goes.

It is recommended that you back up the log immediately before switching the recovery model of your database From FULL TO Simple.

backup log blogs_db_log with truncate_only;
You still have a point in time of recovery if your database goes down during this process.

Step1: Change recovery model of your database to SIMPLE. it will truncate the log
Step2: Shrinking the LOG file to bare minimum.
Step3: Changing the recovery model to FULL.
Step4: If you taking periodic LogsBackups from sql agnet job take a FULL Database backup of your database because your LOG backup will fail since we changed recovery model from
Full>Simple>Full.

Check your logspace on the server
dbcc sqlperf (logspace)
Check Available Free space on all drives
xp_fixeddrives

Example to Shrink your Logfiles.
Step:1
use blogs_db
go
alter database blogs_db
set recovery simple
go
 I am shriking to 2MB You may even opt for 0
(It will shrink to the initial size of your Log file which you assigned while creating your Database log file)

Step:2
dbcc shrinkfile(glogs_db_log, 2)
go

Step:3
alter database blogs_db
set recovery full
go

Optional
Step4: backup database BLogs_DB to DISK
'C:\backups\BLogs_DB.BAK'

Wednesday, August 29, 2012

Restore table from Backup file SQL Server 2005

Few days before I was asked to restore a Table from a backup file? Can you really attain this in sql server 2005? Which is currently under LogShipping.

And then I suggested easiest way to achieve your goal is

1)  Restore backup to another server and apply all the transactions logs with NO RECOVERY and last one with RECOVERY until where you want the data to be recovered.

2) STOP LogShipping.

3) Rename the Table which is corrupted or which you want to restore from Backup file.

4) Export the Table from the RESTORED Database which is in another server to the CURRENT production server.

5) Enable Log Shipping.

You should be good to go.

How to Remove LogShipping SSMS


Ghost Process or Ghost Cleanup Tasks in SQL Server Blocking

Yesterday I got a call from a user about Database not being connected or getting timed out, well actually there are many different solutions for resolving performance issues. 
But the issues what I had was not actually realated to performance there is something else I noticed behind the scene when I ran sp_who2 I had no clue. 

Then I ran select * from sysprocesses where blocked<>0 

to give me the list of blocked processed. 

Then I noticed GHOST CLEANUP process was constantly running and blocking the other SIPD and using most of the resources. 

First lets understand what is Ghost Process  or what are Ghost records. 


Ghost records are the records which are logically deleted but still they exist physically deleted in a page.  Just to give a brief overview, having ghost records simplfies key-range locking and transaction rollback.

The Ghost record is marked with a bit that indicates it's a ghost record and cannot be physically deleted until the transaction that caused it to be ghosted commits or until the transaction is committed. As soon as it is committed, records are deleted by an asynchronous background process (called the ghost-cleanup task) or it is converted back to a real record by an insert of a record with the exact same set of keys.

To Resolve this issue quickly, I disabled the Auto Create Statistics and Auto Update Statistics options on the database. As soon as I hit the apply button the GHOST CLEANUP process stopped.

To me it looks like when SQL tries to create stats or update them, it will run the Ghost Cleanup process first to cleanup the indexes and tables, before getting the stats.


But don't forget to create a job when you are disabling these tasks on the database. Create a job during non-business hours or when the load on the database is minimum.

Tuesday, August 21, 2012

Query to Find out Orphaned Users and Fixing them



When a restore of any database has been performed for example; SERVER A to SERVER B, Users cannot access the database on the SERVER B because they become Orphans even if they have Login ID on the SERVER B, to fix this. 

Run this to find out the list of Orphaned Users

EXEC sp_change_users_login 'Report'




After finding the orphaned users report, run the following command to Fix the Orphaned Users.

EXEC sp_change_users_login 'Auto_Fix', 'user'



To create a new login with password for user it can be achieved by running the below command. 

EXEC sp_change_users_login 'Auto_Fix', 'user', 'login', 'password'













Wednesday, August 8, 2012

Monitoring SQL Server Database Backups

This scripts will give you when was the last time database has been backed up.

select    sdb.name as databasename,
        coalesce(convert(varchar(12), max(bus.backup_finish_date), 101),'-') as lastbackuptime
    from
        sys.sysdatabases sdb
left outer join
        msdb.dbo.backupset bus
    on
        bus.database_name = sdb.name

    group by sdb.name