Wednesday, August 29, 2018

Multiple instances of same windows service on one server

Its possible to host multiple windows service on same server but different name. Here's the link to do it.

Just a small tweak in the code:

        public override void Install(System.Collections.IDictionary stateSaver)
        {
            RetrieveServiceName();
            base.Install(stateSaver);
        }

        public override void Uninstall(System.Collections.IDictionary savedState)
        {
            RetrieveServiceName();
            base.Uninstall(savedState);
        }

        private void RetrieveServiceName()
        {
            var serviceName = Context.Parameters["servicename"];
            if (!string.IsNullOrEmpty(serviceName))
            {
                this._serviceInstaller.ServiceName = serviceName;
                this._serviceInstaller.DisplayName = serviceName;
            }
        }

We can now use this like this:
installutil /servicename=”My Service [SysTest]” d:\pathToMyService\Service.exe
and for uninstall:
installutil /u /servicename=”My Service [SysTest]” d:\pathToMyService\Service.exe
Note for the uninstall you need to supply the servicename so windows how to resolve the service to uninstall

Tuesday, August 28, 2018

Full copy SQL server database from source to destination


1. Copy  databases from source
----------------------------

USE master;
GO 
ALTER DATABASE [DatabaseName]
SET RECOVERY FULL; 

BACKUP DATABASE [DatabaseName]
    TO DISK = 'Backup Location\xyz.bak'  
    WITH FORMAT 
GO  

Copy the back-up file to your destination folder

2. Restore databases at destination
---------------------------------

RESTORE DATABASE [DatabaseName] 
   FROM DISK = 'Backup Location\xyz.bak'  
    WITH RECOVERY,
      MOVE 'xyz' TO  
         'C:\Program Files\Microsoft SQL Server\MSSQL12.SQLEXPRESS\MSSQL\Data\xyz.mdf',  
      MOVE 'xyz_log' TO 
         'C:\Program Files\Microsoft SQL Server\MSSQL12.SQLEXPRESS\MSSQL\Data\xyz_log.ldf'; 
GO

Restore backed up database with different name at destination
RESTORE DATABASE [DPE-OPL] FROM DISK='D:\DB-Backup\4th Sept 2018\SQL\DPE-OPL-INT.bak'
WITH
MOVE 'DPE-OPL-INT' TO 'C:\Program Files\Microsoft SQL Server\MSSQL12.SQLEXPRESS\MSSQL\Data\DATA\DPE-OPL.mdf',
MOVE 'DPE-OPL-INT_log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL12.SQLEXPRESS\MSSQL\Data\DPE-OPL_log.ldf'

3. Rename the DB in Management Studio

Monday, August 6, 2018

Password protect folder using notepad

Just follow the steps in this link
Line no 21: just give a space after password and before goto FAIL.
In the link they are joined.