Monday, December 19, 2016

Part 1: Step by Step guide to create, install & register windows service in visual studio 2013 to read single CSV file and save data in a database table

Points covered in this video are: 

 1. Windows service with pre-defined schedule for reading CSV file data. 
 2. Loading the CSV file data into a data table. 
 3. Using SQLBulkCopy to save the CSV file data into a database table. 
 4. Moving the source file to different folder after successful processing 
 5. Creating an installation setup project using the InstallShield 
 6. Registering the windows service 


1. Single CSV file to be read by windows service 

Saturday, December 17, 2016

Part 11: C# Tutorial – Methods in C#

We will cover following points in this article

1. Why methods
2. Method Signature
3. Difference between static and instance methods


     Why Methods

1. Methods are also called as functions.
2. Method is a code block that contains a series of statements and used to define the
    behavior of a class.
3. Methods are extremely useful because they allow you to separate your logic into 
   different units. You can pass information to methods, have it perform one or more 
   statements, and retrieve a return value. 
4. Methods make application maintenance easier. 

Methods Signature 

< attributes> 
<accessmodifiers> <return-type> <method-name> (<parameters>) 
    //method body 
<access modifiers> - public, private, protected, internal, protected internal 
<return-type>          - void or any valid data type 
<method-name>     - can be any meaningful name except reserved keyword <parameters>         - are optional 

Static vs Instance methods 

1. Static methods are declared using static modifier. Static methods are invoked using 
    the class name. 
2.  Instance methods are declared without using the static modifier. Instance methods 
     are invoked using the instance of the class. 
3. A static method cannot access non-static class level members
4. Instance methods can access static fields. 
5. If a method is declared as static then only one definition of the static method exists in 
    the memory. Multiple instances/objects of a single class can invoke only one       
    definition of the static methods but each objects will have its own separate instance 

Friday, November 11, 2016

Step by Step guide to use SSIS Tool - Import and Export Wizard


SQL Server Data Tools for visual studio can be downloaded using the following link:


An Integration Services catalog (SSISDB) was not found


In this tutorial we will talk about the "Integration Services catalog (SSISDB) was not found" error shown while creating a deployment project.
The error is as follows:
An Integration Services catalog (SSISDB) was not found on this server instance (“ServerName\MSSQLSERVER2012"). To deploy a project to this server, you must create the SSISDB catalog. Open the Create Catalog dialog box from the Integration Services Catalogs node.

Step by Step Guide to Create Windows Service for Writing Data into File based on Insertion in Table


This tutorial follows a step by step approach to show how to create a windows service to monitor insertion into a table, retrieval of the newly inserted records from the table and writing the data into a file as a delimited string.
Step by Step Guide for Creating a Windows Service for Writing Data into a File based on Insertion in Table
General Issues:-
1. How to create a windows service that generates a file as a delimited string in a shared
location based on record insertion in a table.
2. Scheduling the windows service to monitor the Database table for new record insertion and
pick newly generated record and insert into the file as a delimited string
3. Monitoring Windows Service
4. How to Monitor a database table from Windows Service?
Points covered
1. Monitoring Purpose Windows Service
2. Windows Service Creation for Writing Data Into a File
3. Scheduling the Windows Service to Monitor Insertion into a Table
4. Inserted Data into the table will be read from Windows Service Code and the data will be
written to a File


Monday, September 12, 2016

Maintaining ConnectionSetting and AppSetting in separate files in Visual Studio 2013 application

In this tutorial, i will try to separate database connection settings details and application related settings into separate files than keeping it in Web.config file. To do this, first thing i will do is to open the web application in which i want to create separate files

1. Select the project 
2. Right click on project and select "Add -> Add new item"

3. select "Visual C# -> Web Configuration File" option
4. enter the file name as "ConnectionSettings.config" or file name of your choice. and click on "Add" button

5. Enter the database connection setting details into "ConnectionSettings.config" file as shown below
<?xml version="1.0"?> 
 <add name="db" connectionString="Data Source=VAIO\\MSSQLSERVER2012;User ID=sa;    Password=password1; Initial Catalog=AdventureWorks2008R2;
   Persist Security Info=true;"/>

6. Now we will follow the same steps as followed for "ConnectionSettings.config" to add "Settings.config" file

7. enter the following configuration details in "Settings.config" file
<?xml version="1.0"?> 
 <add key="welcomeMsg" value="You are welcome to simplyDotnet"/>

8. Now we need to complete the final step to add the reference to newly added "ConnectionSettings.config" and "Settings.config" file in "Web.config" file:
<connectionStrings configSource="ConnectionSettings.config"></connectionStrings> 
<appSettings configSource="settings.config"/>

9. Add a reference to following namespace in your *.cs file

using System.Configuration;

10. Now we can use following code to read connectionsettings details:


11. We need to use the following code to read appsettings details


  Hope this helps

Sunday, September 11, 2016

Getting started with Windows Service in Visual Studio 2013

Download the tutorial code here: 

Lets start with building a simple windows service in Visual Studio which will write "Hello World" text with current Date and Time stamp into a text file.
  1. Open Visual Studio
  2. Navigate to "File -> New -> Project" menu option

  1. Navigate to "Visual C# -> Windows Desktop" under installed templates options
  2. Select "Windows Service"
  3. Enter "Project Name" and "Location" as shown below

  1. Rename the "Service.cs" file to "HelloWorldService.cs"

  1. Go to code behind file of "HelloWorldService.cs" file and enter the following code:
/// <summary> /// Create instance of timer class and set the interval. /// define the timer elapsed event
/// call the start method of the timer object /// </summary>
public HelloWorldService()
     Timer oTimer = new Timer();
     oTimer.Elapsed += oTimer_Elapsed;
     oTimer.Interval = 6000;
     oTimer.Start(); }
/// <summary> /// define the logic to write the file with "HelloWorld" text with datetime stamp /// </summary> /// <param name="sender"></param> /// <param name="e"></param>
void oTimer_Elapsed(object sender, ElapsedEventArgs e)
 StreamWriter oStreamWriter =   new StreamWriter("G:\\SimplyDOTNET\\ServiceOutput\\HelloWorld.txt", true);
 oStreamWriter.WriteLine("Hello World" + DateTime.Now.ToString());
 oStreamWriter = null;

  • run the service
  • donot close the alert window which is shown

  1. navigate to the folder which is set as a destination to write the text file
  2. you can find a file and if you open it, you will find the text is written to the file

Hope this helps.

Thursday, September 1, 2016

Free .NET assembly browser and decompiler

In this article i will talk about one of the best .NET assembly browser and decompiler, which is absolutely free.

The .NET decompiler name is ILSPY which can be downloaded from

Once downloaded in your local folder, you will be required to extract the files of ILSpy_Master_2.4.0.1963_Binaries.ZIP file. Go the the extracted folder and click on "ILSpy.exe".

As you can see in the above screen shot, mscorlib.dll internal implementation details are decompiled and shown:

For demo purpose, i am selecting the "Open from GAC" option which will display all the dll's registered in GAC of my machine

Once, i select a dll in this case "CrystalDecisions.CrystalReports.Design" dll it will show all the details like references and resource (the code implementation).

All the internal implementation details will be displayed. I loved the idea that this decompiler is free and source is also available for download if you are interested in enhancing the existing features.

Hope this help. Happy Coding and debugging....

Tuesday, June 28, 2016

SQL Server Doesnot exists or Access Denied (SOLVED)

During recent database migration from SQL Server 2005 to SQL Server 2012, we faced a issue where while trying to connect to SQL Server 2012 database from Visual studio was resulting in an error "SQL Server does not exist or acess denied".
After breaking head for some time i could figure out the problem. The problem was related to the attributes used in the connection string. The connection string with old attributes or format was not able to connect to SQL Server 2012 database.
Lets look at the old connection string attributed and new connection string attributes.

The connection string which worked from Visual Studio to SQL Server 2005:

<add key="connection" value="server= VAIO;User ID= test_user;Password=#######;database=master;connection reset=false;" />

"SQL Server does not exist or acess denied" error was thrown when the connection string with same attributes was used to connect to SQL Server 2012 server.

Correction required in Connection string attributes is as follows:
<add key="connection" value="Data Source=VAIO;Initial Catalog=master;Persist Security Info=True;User ID=test_user;Password=#######"/>

The following attribute changes can be noticed:

Old Attribute New Attribute
server Data Source
database Initial Catalog
connection reset Persist Security Info

Hope this helps.