My day-to-day developer tools

There are so many helpful tools, websites for a developer. I use some of them which served me very well and they are FREE.

These are the tools I am using in my day-to-day life.

Pocket: This tool I am using as read later app. Whenever I see something I want to read later I will save in Pocket. The best part of this tool is it sync my entire list to mobile and I can read them offline which is cool.

Feedly : This tool is great way to follow my favorite sites, authors. I use this tool mainly to follow the feeds of programming, tech and science related topics.

Flux: This tools is helpful in reducing stress on eyes by reducing blue light effect. It runs in the background and set the screen brightness automatically based on the time of my current location. The site says

f.lux makes your computer screen look like the room you’re in, all the time. When the sun sets, it makes your computer look like your indoor lights. In the morning, it makes things look like sunlight again.

Tell f.lux what kind of lighting you have, and where you live. Then forget about it. f.lux will do the rest, automatically.

OneNote: This is default note taking app. Using this tool is super easy and helps me organize my work.

Fiddler: This is a web debugging proxy for web platforms and it is very helpful for me to test web sites and web api.

LINQPad: This tool is very helpful in my day-to-day programming life. I use this tool for not only to test LINQ queries but also to run some C# sample code to see the results instead of creating Visual Studio console apps. Site says

Put an end to those hundreds of Visual Studio Console projects cluttering your source folder and join the revolution of LINQPad scripters and incremental developers.

SlickRun: I use this tools many times in a day. It is a floating command line utility which always appear on the screen. You can open any program or site from this tool without going through start menu find program etc. It has auto complete feature and the best part is you can configure for your needs.

GitHub Desktop: I recently started using this tool to create some test projects GitHub. If you are not familiar with Git commands or want to learn Git this tool is super easy to start. Once you are comfortable with this, start using Git commands instead of this tool to get expose to lot of other features of Git. Its fun to use git commands 😉

Bitbucket: If you want to create your personal projects using Git but don’t want to share publicly then this site is very useful. I use this website for my personal projects.

 

 

Advertisements

Export and import database using smo

There will be situation where you want to export data from one database to other database. This can be achieved in my ways but the easiest way to do is using SSMS export/import wizard but there will be situation where you have to export data using code, I mean from your application. Such situations can be easily dealt with using SQL Management Objects (SMO).

The following sample application to work properly you need to refer the following SMO dlls

  • Microsoft.SqlServerConnectionInfo
  • Microsoft.SqlServer.Dmf
  • Microsoft.SqlServer.Management.Sdk.Sfc
  • Microsoft.SqlServer.Smo
  • Microsoft.SqlServer.SmoExtended
  • Microsoft.SqlServer.SqlEnum

Here is the code that shows how to export data from source database to destination database.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo;
using System.Configuration;
using System.Diagnostics;
using IOM.DataGrazer;
using IOM.DataGrazer.Common;
using IOM.DataGrazer.DBHelper;
using System.Data.SqlClient;

namespace ExportAndImportDatabase
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                // Export source database to destination database
                ExportData();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.ReadLine();
        }

        private static void ExportData()
        {
            string sourceConnectionString = string.Empty;
            string destinationConnectionString = string.Empty;
            SqlConnectionStringBuilder sourceConnBuilder = new SqlConnectionStringBuilder(sourceConnectionString);
            SqlConnectionStringBuilder destConnBuilder = new SqlConnectionStringBuilder(destinationConnectionString);

            ServerConnection serverConnection;
            if (sourceConnBuilder.IntegratedSecurity)
            {
                serverConnection = new ServerConnection(sourceConnBuilder.DataSource);

                // Windows Authentication
                serverConnection.LoginSecure = true;
            }
            else
            {
                serverConnection = new ServerConnection(sourceConnBuilder.DataSource, sourceConnBuilder.UserID, sourceConnBuilder.Password);
            }

            Server server = new Server(serverConnection);
            Database database = server.Databases[sourceConnBuilder.InitialCatalog];

            // Define a Transfer object and set the required options and properties.
            Transfer xfr = new Transfer(database);

            xfr.CopyAllObjects = false;

            xfr.CopyAllTables = true;
            ////xfr.CopyData = true;
            ////xfr.CopySchema = true;
            ////xfr.DropDestinationObjectsFirst = true;

            ////xfr.CreateTargetDatabase = true;
            xfr.DestinationDatabase = "DestDBName";
            xfr.DestinationServer = destConnBuilder.DataSource;

            if (destConnBuilder.IntegratedSecurity)
            {
                xfr.DestinationLoginSecure = true;
            }
            else
            {
                xfr.DestinationLogin = destConnBuilder.UserID;
                xfr.DestinationPassword = destConnBuilder.Password;
            }

            ScriptingOptions scriptOptions = new ScriptingOptions();
            scriptOptions.ScriptSchema = true;
            scriptOptions.ScriptData = true;
            scriptOptions.EnforceScriptingOptions = true;
            scriptOptions.DriAllKeys = true;
            scriptOptions.ScriptBatchTerminator = true;
            scriptOptions.ScriptDrops = true;
            //scriptOptions.IncludeIfNotExists = true;

            scriptOptions.WithDependencies = true;
            ////scriptOptions.Indexes = true;
            xfr.Options = scriptOptions;

            xfr.DataTransferEvent += new DataTransferEventHandler(DataTransferEvent_Handler);
            xfr.DiscoveryProgress += new ProgressReportEventHandler(DiscoveryProgress_Handler);
            xfr.ScriptingProgress += new ProgressReportEventHandler(ScriptingProgress_Handler);
            xfr.ScriptingError += new ScriptingErrorEventHandler(ScriptingError_Handler);

            xfr.TransferData();
        }

        static void DiscoveryProgress_Handler(object sender, ProgressReportEventArgs e)
        {
            Console.WriteLine(e.Total + "/" + e.TotalCount + " " + e.Current.Value);
        }

        static void DataTransferEvent_Handler(object sender, DataTransferEventArgs e)
        {
            Console.WriteLine("[" + e.DataTransferEventType + "] " + e.Message);
        }

        static void ScriptingProgress_Handler(object sender, ProgressReportEventArgs args)
        {
            Console.WriteLine("[" + args.Current.Value + "]");
        }

        static void ScriptingError_Handler(object sender, ScriptingErrorEventArgs args)
        {
            Console.WriteLine("[" + args.Current.Value + "]");
        }

    }
}

The above sample exports only tables, keys and its data to destination database. If you want to export everything including stored procedure and functions, make ‘CopyAllObjects = true’  then no need to explicitly mention ‘CopyAllTables = true’ in the above code. The ‘Transfer’ object has four events which can be useful to identity the status of the transfer operation.