2016年11月24日星期四

WP UI Design - Language Selection on Menu Bar

Recently, I was requested to help for changing the language selection display style on the menu. Currently the website shows English on the menu by default, and the second language, which is Chinese, is hidden on the drop-down menu.

Due to the website only support two languages, English and Chinese. Therefore, the owner want to display the second language right on the menu instead of hiding on the drop-down, so that user can switch the language easily. This is reasonable requirement for bilingual website.


Website Language Selection UI Design

It is common approach to place language selection on the menu bar for those websites support more than one language.

    1. Bilingual language support

For English as the first language website, we could place the second language button on the menu bar, as shown on Image 1.  When user click on the second language the page will display in the second language, and show first language button on the menu bar.

Image 1

    2. Multi-language support

In the case of supporting multi-lingual, the first approach is not appropriate due to there are more than one language could be selected. In this case, we have to put all other languages on the dropdown list, so that user can pick one of the other languages as preferred, as shown on image 2.

Image 2

However, I discovered that the website is using WPGlobus plug-in for WordPress. WPGlobus is a great plug-in for supporting multi-language on WordPress site. By design, the language bar always shows in mulit-language style. There is no way to change it into bilingual style, unless WPGlobus supports bilingual style.

2016年11月23日星期三

Sending mail from SSIS

2016-11-19

SSIS toolbox provides Send Mail Task for sending emails from integration service. It allows only sending text mail with SMTP Connection Manager.

SMTP Connection Manager supports only anonymous and windows authentication. If you use mail server outside of the organization boundary or need to send html format mail this task is useless.

Here's the screenshots to describe this limitation.
Send Mail Task

SMTP Connection Manager
The alternative way, we could use Script Task to send mail directly or use Execute Process Task to trigger another process to send mails.

1. Send Mail using Script Task
 
    a) First we create a few variables to pass mail information to the task.

          Note that some ISPs block port 25, in this case you should use alternative port instead.

    b) Pass variables to the task.


    c) Scripts to be executed is as following. The namespace System.Net.Mail is needed in order to send mail.

        using System.Net.Mail;

        public void Main()
        {
            var smtpCredential = Dts.Variables["smtpCredential"].Value.ToString();
            var mailServer = Dts.Variables["mailServer"].Value.ToString();
            var mailPort = Dts.Variables["mailPort"].Value;
            var mailSender = Dts.Variables["mailSender"].Value.ToString();
            var mailRecepients = Dts.Variables["mailRecepients"].Value.ToString();
            var mailSubject = Dts.Variables["mailSubject"].Value.ToString();
            var mailBody = Dts.Variables["mailBody"].Value.ToString();
           
            var credential = smtpCredential.Split(',');
            var receipients = mailRecepients.Split(',');
            var user = credential[0];
            var pwd = credential[1];
            bool isHtml = true;

            MailMessage mail = new MailMessage();
            mail.IsBodyHtml = isHtml;
            mail.Subject = mailSubject;
            mail.Body = mailBody;
            mail.From = new MailAddress(mailSender);
            foreach (var m in receipients)
            {
                mail.To.Add(m);
            }

            SmtpClient smtp = new SmtpClient(mailServer, (int)mailPort);
            smtp.UseDefaultCredentials = false;
            smtp.Credentials = new System.Net.NetworkCredential(user, pwd);
            smtp.EnableSsl = false;
            smtp.Send(mail);
           

            Dts.TaskResult = (int)ScriptResults.Success;

        }

2. Send Mail using Execute Process Task
    
    By specifying the executable location, and optionally pass in some arguments, the task will trigger the other process to send mails. This especially useful in Service-Oriented Architecture.


Conclusion, there are many approaches for sending any kind of mails from integration service (SSIS) other than Send Mail Task.

2016年11月22日星期二

SQL Server Database Backup - 3 Methods

2016-11-1

Database backup is not the DBA only work. Most of developers and even small business owners also need to perform this task. This article will introduce 3 methods to back up database from SQL Server.

  1. Method 1 – from management studio
    1. Connect to database server
    2. Expend Databases folder



                3.       Right click on the database that you want to backup
                4.       from Context menu click Task
                5.       from sub menu click on Back Up…


               6.       on the popup window click on Add

               7.       on Select Backup Destination window you could enter file location and file name directly or click on … button to specify a backup file.
               8.       Click on OK button to close the window, then click on OK again and wait for the completion.


   2. Method 2 – using T-SQL script

You could either to execute the script on Management Studio or store it as stored procedure to execute.
Here’s the script for backing up all user databases:

DECLARE @name VARCHAR(50) -- database name 
DECLARE @path VARCHAR(256) -- path for backup files 
DECLARE @fileName VARCHAR(256) -- filename for backup 
DECLARE @fileDate VARCHAR(20) -- used for file name

-- specify database backup directory
SET @path = 'C:\DB\MSSQL11.MSSQLSERVER\MSSQL\Backup\' 
SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),112)

DECLARE db_cursor CURSOR FOR
SELECT name
FROM master.dbo.sysdatabases
WHERE name NOT IN ('master','model','msdb','tempdb')  -- exclude system db

OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @name
WHILE @@FETCH_STATUS = 0
BEGIN
       SET @fileName = @path + @name + '_' + @fileDate + '.BAK' 
       BACKUP DATABASE @name TO DISK = @fileName
       FETCH NEXT FROM db_cursor INTO @name
END  
CLOSE db_cursor
DEALLOCATE db_cursor


    3. Method 3 – using SSIS Service

In order to use SSIS Service, you need SQL Server Development Tool (SSDT) or SQL Server Business Intelligence Development Studio (BIDS) for SQL 2008 and older to create a package. You can deploy the package to SQL Server and schedule a job to auto-run it.

          1.       Create a SSIS project from Visual Studio (SSDT installed). Note that the project template is under Business Intelligence folder, not SQL Server.

        2.       Create a package and open it, drag and drop “Back Up Database Task” onto the Control Flow work space.
        3.       Double click on the task, “Back Up Database Task” window will popup.



           4.       Click on New… button to specify the database connection.




              5.       On “Back Up Database task” window click on Database(s) drop down button, and select the database option you want to back up.


                  6.       In Destination tab, specify Folder location and click OK.

               7.       Save the package.


               8.       You could execute the task right inside the studio. Right click on the task and select Execute Task from context menu.


                    You will see the green check mark when the execution completed.


              9.       Now you can run the package or debug the package directly in the Visual Studio, or you can deploy the package to SQL Server to run.