Thursday, May 26, 2016

Configure Database Mail in SQL Server

How to configure Database Mail in SQL Server ?

Introduction : Database mail is a SQL Server component that uses the 'Simple Mail Transfer Protocol' or SMTP to send email messages. Follow the below given steps to configure database mail:

STEP 1 : Connect to SQL Server Management Studio (Preferably run as Administrator). Go to Management and double click on Database Mail. A wizard as shown below will open. Click Next.


STEP 2 : Select Configuration Task window will appear. If you are installing Database Mail for the 1st time select the set up option radio button : Set up database mail by performing the following tasks. In case you want to modify or manage a previously configured database mail chose other options as applicable to you.


STEP 3 Choose Create a new account :


STEP 4 : Provide the following values

Account Name : Any Name
Description : Optional
Email address : Your Email Address
Display Name : Any Name
Reply Email Address : Optional
Server Name : Where\How to get server name is described below :
Port : Usually 25
Tick server requires SSL
SMTP Authentication Method : Choose any, I have chosen basic authentication


Now  Where\How to get server name ? The easiest approach :

Send a mail from your outlook in the format : wrongname@yourcompany.com (Please note that part of email id before @ should be wrong and not the part after @ )

You will get back MAIL DELIVERY FAILURE MESSAGE as shown below from the Server. Find the GENERATING SERVER name in this mail.



Provide this server name in Server Name.

STEP 5 : Complete the wizard. Finish.


And you Database mail is configured now.

Now lets TEST : Run this query to test :


EXEC msdb.dbo.sp_send_dbmail 

 @recipients='Provide email id here whom you want to send mail',  

 @profile_name = 'Account Name you gave in STEP 4',  

 @subject = 'Any Subject Line',  

 @body = 'Type Message Body Text',  

 @file_attachments='Attachment Full File path with file name';

The recipient must receive mail provided if all is good. To check the quue and status of mail like : Sent\Unsent\failed\Retry etc, Run this query :

USE MSDB
GO

Select * from sysmail_allitems


To check error messages :

USE MSDB;
GO

SELECT items.subject,
    items.last_mod_date
    ,l.description FROM dbo.sysmail_faileditems as items
INNER JOIN dbo.sysmail_event_log AS l
    ON items.mailitem_id = l.mailitem_id
WHERE items.recipients LIKE '%%' 
    OR items.copy_recipients LIKE '%%'
    OR items.blind_copy_recipients LIKE '%%'
GO
 In some cases if you are using ssis send mail task or using a ssis job to send mails with attachment; the SQL Server account or SQL Server Agent User may not have access to the Folder from which you are taking the file to be attached. You may get error : SQL Service account not having the correct access to the shared drive :

To solve this :

Grant access to the folder


NT SERVICE\MSSSQLSERVER if running SSIS Package or Running a SQL SERVER to send mails :
If using SSIS JOB then add NT Service\SQLSERVERAGENT User :

Follow the screenshots :

STEP 1 : Right click the folder containing the attachment and go to properties Click Edit then Add :




STEP 2 : Browse for NT SERVICE\MSSSQLSERVER or NT Service\SQLSERVERAGENT, change location if required; Check Names and OK: Once users added tick Full control and Modify under Allow : Apply




That's it.

Thanks for reading. Please like and follow & Suggest improvements.

Follow me on twitter @msbigyan

Thanks.
Paras Singh
Senior Consultant : BI & Analytics

Saturday, April 30, 2016

SSIS 2016 - Exploring New Features

In this Blog we'll list out 11 new much awaited features in SSIS 2016.

Note : By the time I am writing this blog SQL Server 2016 (RC3) and CTP 3.3 is there in the market.

1. Incremental Package Deployment : 

In SQL Server 2005 and 2008 we used to deploy either through file system or to the msdb database. We used to deploy a package at a time and if we need to delete\update\add a new package, we simply were able to deploy that 1 package. But tin 2012 and 2014 we had to deploy the entire project containing all many packages at one go. The drawback was even if 1 package is changed the entire project had to be deployed again.

Thankfully in 2016 we can deploy entire project in one go as before and we also now have the flexibility to deploy package-by-package.



2. Separate Installation of SQL Server Database Engine and SSDT

Compared to SQL SERVER 2005, 2008 we used to install SQL Server Database Engine and BI Tools in one go by just selecting the features; SSDT is installed separately in SQL Server 2012, 2014 and continues in 2016.

3. Custom Logging Level in SSIS Catalog

Previously we had 4 built-it logging levels to choose from : Basic, Performance, Verbose and None. Now we can create multiple custom logging levels and save them to use\choose while running packages. Hence it is flexible, reusable, portable and easy to use. While creating custom logging level we have 3 categories of statistics to choose from : Executable Execution Statistics, Component Data Volume Statistics & Component Execution Statistics. 



To show custom logging levels we now also have a new view catalog.cutomized_logging_levels.

A new role ssis_logreader role has also been introduced.

4. SSDT - Visual Studio 2015 accommodates all different versions in single installation :

No more requirements for installing several versions of SSDT. In configuration properties we can now choose TargetServerVersion as SQL Server 2012, SQL Server 2014 or SQL Server 2016.



5. Column Name in error output : 

Now we have full path to error (Error Column - Description) column in output not just column id. Great help in debugging and identify the bad columns.

6. Package Parts : 

We can now create a new control flow package part file (.dtsxp)  and save it for reuse if something is to be reused multiple times. It will reflect in Package Parts folder and also in SSIS Control Flow Tool Box under package parts. Note that it is visible only for that project only.

7. Explicit Support for Excel 2013 and Excel 2016

8. Connection Mangers for HDFS : 

For performing common HDFS operations we have connection managers to connect to hadoop clusters and tasks.

9. SQL Server Import Export Wizard : 

Now we can import\export data to\from Azure Blob storage using Import Export Wizard

10. Project Upgrade : 

When we upgrade from prev version to current version project level connection mangers work as expected, Layout and annotations remain unchanged.

11. Enable Always on support for Integration services catalogs :



Thanks you for reading. Please like and comment
Paras Singh

Follow me on twitter @msbigyan

Thursday, April 28, 2016

Create Virtual Machine on Microsoft Azure and connect in minutes

This is a step by step illustration of how to Create Virtual Machine on Microsoft Azure and get started in minutes with 15 steps :

STEPS WITH SCREENSHOTS :

STEP 1 :

Login to new Azure Portal

STEP 2 : Virtual machines --> Add


STEP 3 : Search the Windows Server with the Software of your choice with which you want to provision your machine. Here I have selected "SQL Server 2016 RC3 Evaluation on Windows Server 2012 R2"

STEP 4 : Select a Deployment model : Resource Manager or Classic. Every resource you create through resource manager exists within a resource group. Click on Create.

STEP 5 : Configure Basic Settings : Provide Name, User name, password : "Remember the password". In resource group select any existing resource group which you made earlier or make a new one. Select a location.


STEP 6 : Choose VM Size. Make a wise choice based on cost.


STEP 7 : Configure Optional features : You can go with defaults.

STEP 8 : In may case I have to configure SQL Server settings. I go with defaults.


STEP 9 : Check summary. If you want to modify click on previous steps and do again :


STEP 10 : Deployment usually takes some time. For me it took 4-5 minutes. Check Notification



STEP 11 : Final blade will look like this : Look at the 3 important links on top : START, STOP and CONNECT. 


STEP 12 : Click on Connect. This will download a .rdp . Click open to connect(RDP) to your Virtual Machine.

STEP 13 :

STEP 14 :


STEP 15 : That's it : ALL SET Your Virtual Machine is ready to use now.

In case you want to download anything on your Machine you need to disable "IE Enhanced Security Configuration" and then you can use your Internet Explorer to download :



Thanks,
Paras Singh
Note : Please leave your comments\suggestions and like this post

Follow me on twitter @msbigyan