Tuesday, 28 September 2010

Send Email from SQL server

exec master.dbo.xp_sendmail
@recipients ='myasin@clash-media.com',
@subject = 'testing SQL Server Emails',
@message = 'Free space on Z Drive has dropped below 2 Gigabyte'

will get error message if on 64-bit version:
"SQL Mail does not work with the 64-bit version of SQL Server"

Instead Can use:
Profile Name is the setting in:

[database] -> Management -> Database Mail -> Configure Database Mail


EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'SQLServerDatabaseMailProfile',
@recipients = 'muhammad.yasin@clash.com',
@body = ' is scheduled to be renewed in 120 days - GET TO WORK!',
@subject = 'testing by yasin'

Get all Active Users, Query detail and Kill active session

Find out who is currently connected with SQL Server and is Active.

sp_who2 active

To get the detail of one particular process ID
sp_who2 96

Get the detail of query running by any process ID found by above query:

dbcc inputbuffer(96)

To Kill session use:

Kill 96

Get Free Space Available on Database server

Use this SQL Command to find the free space available on each drive on hard disk of database server:

Exec master.dbo.xp_fixeddrives