Thursday, April 13, 2017

Excel: How to remove empty area and make worksheets nicer for printing

Almost time when using Excel, I need to print its worksheets as result of my work.

But sometimes, I use File >> Print Preview to see what the document will look like if I print it, I often see that the document gets many extra blank pages or the columns broken into new pages. If I save the document as a .pdf file, the problem persists in the .pdf file. It's worse.

However, Excel has Page Layout functions groups to help us make worksheets nicer. Below are 2 functions I often use:
  • Page Layout >> Page Setup >> Print Area >> Set Print Area: select area which you want to print and use this function
  • Page Layout >> Scale to fit >> Width: should be set to 1 page, it will help to avoid broken columns.


There are a lot of functions there which you can try and see until you feel it's good.
Yes, let remember to use Print Preview function to check again before printing any document.
Any comment is welcome.

Bye, nice day!
Hung

Wednesday, March 29, 2017

How to use Azure File Storage as a backup disk on Windows Server

Azure File Storage (AFS) is a file storage service hosting on Azure cloud, it can be used for backup data, files or accessing files like S3 of Amazon.

In this article, I'll show you how to create a storage, map it as a local disk on Windows Server and backup files in a schedule.

1. Create a storage

Login to your Azure portal >> click Storage accounts menu >> click plus +Add button


Below is an example for a standard storage with lowest cost. You can see Azure Storage Pricing for more details.

Once done, open the storage and copy Access keys (can copy key 1 only):

2. Map the storage as local disk

Open cmd tool and run the command like below to map the storage s a local disk on Windows Server:
net use X: \\xxxStorageName.file.core.windows.net\xxxFileFolder /u:xxxStorageName xxxKey

In which:
X: is the letter of the local disk mapped
xxxStorageName: name of the storage you keyed in step 1 (see Create storage account picture)
xxxKey: access key

To disconnect this disk, use below command:
net use X: /delete

3. Create a .bat file and put into a Task Scheduler

For example, I want to copy logs file from a folder on another disk to this storage disk. So I create a .bat file naming copylogs.bat with content as below:
@echo off
copy D:\daily\*.log X:\daily
del D:\daily\*.log

After that, I create a Task Scheduler to run this .bat file on 1 AM daily:

It's simple. Hope you can save your data or files on the cloud. It's worth when your server is damaged or something like that.

Any comment is welcome!

Monday, January 9, 2017

Install Microsoft Security Essentials In Windows Server 2008 to 2012 R2

Microsoft Security Essentials (MSE) is free tool to help guard your Windows computer against viruses and other malware. In previous years, MSE is not in the list of top security guys for Windows, but now Microsoft is investing a lot on security problem and it is running to the top. So it is worth to have MSE on your Windows server to protect your server. MSE also rather doesn't take many resource vs. the other antivirus program, so it doesn't impact much on server performance.

But unfortunately it runs only on Windows desktop. It cannot run on Windows server by default. However, you can make it serves you by the following steps:

1. Go to this link: https://support.microsoft.com/en-us/help/14210/security-essentials-download then choose right version for your server (32 bit or 64 bit) and download mseinstall.exe

2. Use Administrator user, right click on mseinstall.exe then choose Properties menu

3. Select Compatibility tab, then choose Run this program in compatibility mode for Windows 7. Then click OK.

4. Use command prompt, change folder to the folder containing mseinstall.exe then run below command:
mseinstall.exe /disableoslimit

5. Follow next steps and enjoy MSE installed on your Windows server.

You can download a test EICARs file on the link: https://www.eicar.org/86-0-Intended-use.html for checking if MSE is working.

Note for updating MSE:
When running Windows Update, you may see new update for MSE but the installation will be failed.
After Windows Update tried & failed, open the folder: C:\Windows\SoftwareDistribution\Download\Install, then you may see UpdateInstall.exe file, let do step 3 & 4 above for this file, then you can install new update.

Good bye and good luck!
Any comment is welcome.


Wednesday, December 28, 2016

Windows Server 2012: turn off auto restart after logging in

By default Windows Server will auto download new update and auto restart after you log in if the update requires to restart the server. This can cause some unwanted problems such as some applications cannot run after restarting, users complains etc.
You can change this default behavior by policies in Local Group Policies. Below are steps:
  1. Press Windows Key + R to open the run prompt.
  2. Type "gpedit.msc" and press enter.
  3. Navigate to Computer Configuration >> Administrative Templates >> Windows Components >> Windows Update.
  4. Enable the "Configure Automatic Updates" policy and set it to "2 - Notify for download and notify for install".
  5. Enable the "No auto-restart with logged on users for scheduled automatic updates installations" policy.

See the following image for example:

Have a good time!
Happy new year!

Wednesday, November 23, 2016

ETL and Build Data Warehouse with SSIS - Part 2

This article is a continue of Part 1. Here I will show you how to Parameterize, Load Data Into Destination Using Look up, Deploy SSIS Package on SQL Server and Create Agent Job.

1. Parameterize

In the sample of merging Excel file with data table, we have 2 connections: Excel Connection (for reading data from Excel source file) and OLE DB Connection (for reading data from data table source). These connections can be changed especially when you deploy your SSIS Project on SQL Server. So it needs to be parameterized.

To parameterize a connection, let right click on it (in the bottom of a design screen of a package) the select Parameterize:
In the screen showed up, let specify values for the connection parameterized. As my experience, connections should select as Project level (apply for all packages in the project) and Required (to make sure it must be set before executing a package):

After that, you can see the parameter created in Project.params. You can add other parameters in here. For example, I added 2 new parameters Sell_StartDate and Sell_EndDate to use in next section:


2. Load Data Into Destination Using Look up

In this section, we will transform products sold in a period from SSIS_Demo_Products table to new table SSIS_Demo_Products_Report (assume that it will be used for report purpose). But before loading data into SSIS_Demo_Products_Report, we will look up its data to check if existing data matches with new data or not. Then we will insert or update data.

First, create New SSIS Package (e.g. LookupAndLoad.dtsx) >> drag Data Flow into >> double click >> drag OLE DB Source into >> configure it:

Note: We use $Project::Sell_StartDate and $Project::Sell_EndDate parameters (created from above step) for SQL command.

Drag Lookup task into, connect OLE DB Source to it then configure it:

Note: we just need to lookup on ID column.

Now we drag OLE DB Destination into >> connect Lookup to it >> select its input as Lookup No Match Output containing new records >> configure it as below to insert new records into SSIS_Demo_Products_Report:

Next, let drag OLE DB Command into >> connect Lookup to it >> select its input as Lookup Match Output containing existing records >> configure it as below to update existing records:

After done, we have final diagram of Data Flow as the following:

Here are tables before right click Execute Task:
And after executing task:

2. Deploy SSIS Package on SQL Server

2.1 Create an SSISDB catalog, if you haven’t already. Below are steps:
  • Open MS SQL Server Management Studio.
  • Connect to the SQL Server Database Engine.
  • In Object Explorer, expand the server node, right-click the Integration Services Catalogs node, and then click Create Catalog.
  • Click Enable CLR Integration. The catalog uses CLR stored procedures.
  • Click Enable automatic execution of Integration Services stored procedure at SQL Server startup to enable the catalog.startup stored procedure to run each time the SSIS server instance is restarted. The stored procedure performs maintenance of the state of operations for the SSISDB catalog. It fixes the status of any packages there were running if and when the SSIS server instance goes down.
  • Enter a password, and then click Ok. You'll see this catalog under Integration Services Catalogs. (Make sure SQL Server Integration Services is started).
2.2 Build SSIS project. On MS Visual Studio, right on your solution and Build Solution. Goto bin\Development folder of your solution, then copy .ispac file (e.g. SSIS Demo.ispac) to SQL server.

2.3 Deploy SSIS project to SQL server. On MS SQL Server Management Studio, right click on SSISDB catalog >> select Create Folder >> input folder name (e.g. SSIS_Demo) and click OK >> click on new created folder >> right click on Projects >> select Deploy Project >> click Next button on the popup windows >>  Browse to select .ispac file >> click Next button to deploy, it may show a warning, just click OK to skip >> click Next button >> last step, click Deploy button then click Close button:

2.4 Create Environment & setup Parameters.
  • Explore new created folder (e.g. SSIS_Demo) >> right click Environments >> select Create Environment >>:
  • Give it a name (e.g. Development), then click OK:

  • Right click on new created environment (e.g. Development) >> select Properties: >> click tab Variables >> copy and paste the names & values of parameters in SSDT to here >> then click OK:


Note: For parameter of connection string (e.g. ExcelConnectionManager_ConnectionString), you should change the value to new source.
  • Configure parameters of the project. Right click on the project (e.g. SSIS_Demo) then select Configure >> add Development environment into References >> open Parameters section >> choose corresponding variable from the environment:

  • Let execute packages to see if it works. Right click on a package and select Execute. It will alert to choose a correct environment:

3. Create Agent Job

The last step is to set up an Agent Job to run a package on a schedule. Make sure that SQL Server Agent service is running. Below is series of images for creating an Agent Job:

After creating the job, let check if it can work:

Done! Now you can start to build your Data warehouse!

Good luck. Any comment is welcome.

Subscribe to RSS Feed Follow me on Twitter!