Posts

Showing posts from May, 2013

Send emails with SQL Server using Html files

Image
Sending emails from MS SQL Server using the Database Mail is easy. Once the Database Mail is active and configured (see this blog for quick configuration) the emails can be send using the SQL script below: USE msdb GO EXEC sp_send_dbmail @profile_name='EmailProfile', @recipients='test@example.com', @subject='Test message', @body='This is a test message.' In cases where there is a need to send emails in html format - creating the content inside of SQL script is not so convenient. With the help of OPENROWSET function we can read the content of html file, which contains the properly formatted and tested html. For example below is the html file that we can easily open in the browser and validate it displays correctly the way we want. It contains the html and body tags which wraps the content that will be inserted into the email’s body. Test Email This is a test message Below is the SQL script which will send the emails by readi

Create Google Charts in Asp.Net MVC by generating JSON data on the SQL SERVER

Image
The purpose of this article is to share the implementation of Google Charts with data retrieved from SQL Server whereas JSON is created on the SQL Server. Google chart tools provide a rapid way of creating charts from some data for the web developers. All charts are populated with data stored in a DataTable object. The DataTable object can be filled with data using JSON format. There are several different ways of creating and populating a DataTable and they all have some advantages and disadvantages (more about it here ). The application I needed to add Google Charts to be Asp.Net MVC using nHibernate with MS SQL Server. The idea is to create all required data on the SQL Server using stored procedures to gain performance benefits, minimize the efforts of creating JSON for each chart and realize the DRY principal. Once the required SQL stored procedure is created we are going to convert the result table data into JSON and pass it into our DataTable constructor. Let’s say we