Azure SQL Database (SAS) Backup/Restore

This is tricky. Azure SAS SQL Database has master database only. If programmer is taking any advantage of MSDB databases or synonmous, it will not work there directly.

Use Deploy Database to Microsoft Azure SQL Database

The simple method to restore to Azure SQL Database is;

This will create a new database on Azure SQL Server. You can rename it to your actual database.

Migrate to Azure SQL by restoring from Database

This method requires Azure storage account.

Create a blob storage. Upload database backup. From SQL Management Studio, right-click to [YourLOCALDatabase] and open Tasks>Export Data-tier Application. You can export your database to Azure Blob Storage on this wizard. After backup, connect your Azure SQL Server from SQL Management Studio. Go to your [YourREMOTEDatabase], right-click Databases folder from treeview and go to Import Data-tier Application. Choose your backup file from Blob Storage and enjoy!

This will create a new database on Azure SQL Server. You can rename it to your actual database.

Use Azure Data Migration Assistant Tool

This is unlike other methods mentioned above. This is the most efficient tool for migration databases to Azure SQL. This gives you a chance to select individual objects (tables, stored procedures, views, functions etc). Here is the link;

https://www.microsoft.com/en-us/download/details.aspx?id=53595

This does not create a new database but copy schema and data to existing database.

Use 3dr party tool

3rd party tools can be used to backup/restore Azure SQL database. Here is the list;

https://sqlbackupandftp.com/

The tool allows us to create azure backup on local/remote. We can restore those backups on local/remote machine. I have a schedule job on my local that run everyday 10:00AM to create full backup in Azure blob container “myContainer”.

This tool also allows you to backup on your local computer.

Other methods that can be used with Azure SQL Database;

  • SQL Server Import and Export Wizard
    • Simple process
    • Works even with old SQL Server / SSMS
    • Can export data into different file formats
    • Only data is imported, all other objects will be lost
    • Requires SQL Server Management Studio
    • Manual procedure

Use if you need to move data from Azure to a specific destination (e.g. your old SQL Server) or in a particular format (e.g. flat file) with SQL Server Management Studio tools

  • SSIS Tools
    • Can export data into different file formats
    • Can be run unattended/automatically
    • Only data is imported, all other objects will be lost

Similar to SQL Server Import and Export Wizard, but enables automatic process

Use when you need to create BACPAC file with SQL Server Management Studio tools

  • SqlPackage utility
    • Creates the most exact copy of the database
    • Can be run unattended/automatically
    • Requires the latest DAC library installed
    • Creates a specific BACPAC file

Use if you need to create BACPAC file from a command line

  • BCP utility
    • Can export data into different file formats
    • Can be run unattended/automatically
    • Only data is imported, all other objects will be lost
    • Imports only one table at a time

Use if you need to save data from one or several tables in a readable format

  • SqlBackupAndFtp
    • Simple UI
    • Can create scheduled backups
    • Doesn’t require DAC library installed
    • Creates a specific BACPAC file

Use when you need to perform automatic backups into BACPAC file regularly

  • From Azure Portal
    • Everything online, no software installation required
    • Creates a specific BACPAC file
    • Azure storage account is required

Suitable if you only have a browser

Use AzCopy

This tool can be used to transfer data between storage accounts. Here is the link;

https://adamtheautomator.com/azcopy-setup/

Azure Storage Explorer

This is a GUI that can be used to move files between storage accounts and premises. Here is the link;

https://azure.microsoft.com/en-us/features/storage-explorer/

Windows 10 screenshots

We can capture the screen and use a program, for example Greeshot, to open captured image.

Here are the tips to capture screen;

Print Screen 

The easiest way to take a screenshot on Windows 10 is the Print Screen (PrtScn) key. To capture your entire screen, simply press PrtScn on the upper-right side of your keyboard. 

The screenshot will be saved to your Clipboard.

Windows + Print Screen

To take a screenshot on Windows 10 and automatically save the file, press the Windows key + PrtScn

Your screen will go dim and a screenshot of your entire screen will save to the Pictures > Screenshots folder.

Alt + Print Screen 

To capture only the active window you’re working in and copy it to your Clipboard, press Alt + PrtScn

Snip & Sketch tool

To activate Snip & Sketch, use the keyboard shortcut Windows Key + Shift + S. Your screen will dim and a mini menu will appear at the top of your screen, giving you the option to take a rectangular, free-form, window, or full-screen capture. 

Game Bar 

The Game Bar is an overlay you can use within most Windows 10 apps and games to take screenshots and record video. To open the Game Bar, press Windows Key + G

Power + Volume Up 

To take a screenshot on Windows 10 with a Microsoft Surface device, press the Power Button + Volume Up Button. The screen will dim, and your screenshot will save to the Pictures > Screenshots folder. 

Third-party screenshot apps for Windows 

If you’re unsatisfied with any of the built-in Windows methods, there are third-party screenshot tools worth considering.;

  •  GIFs, take full-page screenshots, and more. The downside? The premium version costs $50. There’s also a 30-day free trial, although any picture you capture during this trial will be watermarked.
  • Lightshot is a free screenshot tool designed for quick social sharing. When you download and install Lightshot on Windows 10, it replaces the Print Screen function and offers more editing capabilities.
  • Greenshot is another free tool that allows you to edit and customize screenshots, as well as the option to capture a complete scrolling web page.

Fix Name Pipes Provider, Error: 40

Today I have received this error on a remote server connecting from my local computer;

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and the SQL server is configured to allow remote connections. (provider: Named Pipes, Provider, error:40 – Could not open a connection to SQL Server) (Microsoft SQL Server, Error: 2).

To fix this error goto start menu–> go to  Microsoft Sql Server –> go to configurations folder and click on sql server configuration manager. check below image.

Expand Sql Native client 11.0 Configuration manager. In client protocols you will see TCP/IP, named Pipes,Via disabled, enable those

Expand Server Network Configuration In Protocols for Sql Server here  Enable Shared,Named,TCP/IP

Expand Sql Native client 11.0 Configuration manager. In client protocols you will see TCP/IP, named Pipes,Via disabled, enable those  and restart the Sql related services. Now the error fixed.

Resources

https://www.c-sharpcorner.com/article/resolve-error-40-could-not-open-a-connection-to-sql-server/

jQuery selector change not firing

I like to fire a change event when “#btnBrowse” click event fires. Here is a sample jQuery code;

$("#btnBrowse").click(function () {
   $("#btnReset").click();
   $("#xFileUpload").click();
});

$("#xFileUpload").change(function () {
   var filename = $('#xFileUpload')[0].files[0].name;
   filename = filename.replace(/\.[^/.]+$/, "");
   //alert(filename);
   $("#xFilename").val(filename);
   fileDoc.fileName = filename;
   fileDoc.fileContnet = $("#xFileUpload").get(0).files;
 });

It turns out that click event will be registered and fired on first click only. For subsequent clicks, I have to registered a change event and triggered it like this;

$("#btnBrowse").click(function () {
   $("#btnReset").click();
   $("#xFileUpload").click().trigger("change");
});

The cons of using this approach. It will work fine for the first click but all subsequent clicks will fire a change event on click event. The reason jQuery has registered two events for the element and execute them simultaneously.

The objective is to grab file from file system. The user should be able to use same file multiple time. The best alternative to achieve this objective is to clear the contents of HTML input type rather tweaking jQuery;

This is HTML file input;

<input type="file" id="xFileUpload" name="xFileUpload" class="form-control" style="display: none" />

This is jQuery code that will clear contents of this file;

$("#btnImportReset").click(function () {
   $('#xFileUpload').val('');
});

This is your final browse script section;

$("#btnBrowse").click(function () {
   $("#btnReset").click();
   $("#xFileUpload").click();
});

Since we are clearing out HTM contents and jQuery is smart enough to figure out change. The change event will be fired this time automatically with a change in HTML file input.

Resources

https://stackoverflow.com/questions/19194177/jquery-select-change-not-firing

https://stackoverflow.com/questions/4247264/how-to-trigger-jquery-change-event-in-code

Allow users to add favorite posts in wordpress

First thing you need to do is install and activate the WP Favorite Posts plugin. For more details, see our step by step guide on how to install a WordPress plugin.

Upon activation, you need to visit Settings » WP Favorite Posts to configure plugin settings.

First option on the settings page is to enable ‘Add to favorite’ option for registered users only. You need to leave this unchecked if you want all visitors to see the ‘Add to favorite’ button.

Next, you need to choose where to show the ‘add to favorite’ link. The plugin can automatically show it before or after the post content. Advanced users can also choose custom method and use <?php wpfp_link() ?> template tag inside WordPress theme files.

Now you need to choose the image icon you want to show next to ‘Add to favorite’ link. The plugin comes with a few images that you can use. You can also upload your own image or don’t show any image at all.

After that you can choose the number of posts you would like to show on your favorite posts page. The default option is 20, you can change that if you want.

Lastly, you can enable or disable statistics. You will need to keep it enabled if you want to show most favorited posts in the sidebar widget.

Don’t forget to click on the ‘Update Options’ button to store your settings.

You can now visit any single post on your website and you will see the Add to Favorite link.

Showing Most Favorited Posts in WordPress

You may want to show your most favorited posts in your blog’s sidebar. Here is how you would do that.

Head over to Appearance » Widgets page. Under the list of available widgets you will notice ‘Most Favorited Posts’ widget. You will need to drag and drop this widget to a sidebar. If you need help adding widget, then check out our guide on how to add and use widgets in WordPress.

You can select the number of posts you want to show in the widget. Don’t forget to click on the save button to store your widget settings.

You can now visit your website to see the most favorited posts in your blog’s sidebar.

Showing a User’s Favorite Posts in WordPress

This plugin stores favorite posts for non-registered users in cookies. For registered users, it saves their favorite posts in your WordPress database.

Here is how you can show each user their favorite posts on your site.

Head over to Appearane » Widgets page and add ‘Users Favorite Posts’ widget to a sidebar.

Resource

https://www.wpbeginner.com/plugins/how-to-allow-users-to-add-favorite-posts-in-wordpress/