Monday, December 4, 2017

Same Method name in 2 interfaces, Implemented in one class

This is a tricky Question,  if I create 2 interface with same method name, and implement both in one class. Now if create object of this derived class, which method it will pick-up/Execute at run time.

To test this need to create 2 interface with same method Name.

 interface IFace1
    {
        void GetFaceDetails();
    }

    interface IFace2
    {
        void GetFaceDetails();
    }

Now create a class to implement both interfaces

public class DerivedClass : IFace1, IFace2
    {
        public DerivedClass()
        {
            Console.WriteLine(" Constructor Called. ");
        }
       void IFace1.GetFaceDetails()
        {
            Console.WriteLine(" IFace1.GetFaceDetails ");
        }
        void IFace2.GetFaceDetails()
        {
            Console.WriteLine(" IFace2.GetFaceDetails ");
        }
    }


Now to use this if I create an object of IFace1 then It will call IFace1.GetFaceDetails Method.
IFace1 obj1 = new DerivedClass();
            obj1.GetFaceDetails();

So it will print " IFace1.GetFaceDetails "

Similarly if I  create an object of IFace2 then It will call IFace2.GetFaceDetails Method.
IFace2 obj2 = new DerivedClass();
            obj2.GetFaceDetails();

So it will print " IFace2.GetFaceDetails "


Now what if I create an object of DerivedClass itself.
DerivedClass obj = new DerivedClass();
obj.GetFaceDetails();


In above code it will show a compiler error that GetFaceDetails Method doesn’t exists in DerivedClass. So it will not execute at all. Or you will have to create another method with same name in class, and compiler will pick that method in execution.

Friday, December 1, 2017

Azure SQL Elastic Pool 

Azure SQL Database is PAAS service, It has  Azure SQL Server and inside this SQL Server we have SQL databases.  The costing for SQL Server Database is based on size and DTU. The Edition (Basic, Standard and Premium) & Pricing Tier (DTUs) as used for costing.

Database Transaction Units (DTU)
Microsoft guarantees a certain level of resources for that database (independent of any other database in the azure cloud) and providing a predictable level of performance. This amount of resources is calculated as a number of Database Transaction Units or DTUs, and is a blended measure of CPU, memory , I/O (data and transaction log IO).
DTUs are most useful for understanding the relative amount of resources between Azure SQL Databases at different performance levels of a database equates to doubling the set of resource available to that database. For e.g. a premium P11 database with 1750 DTUs provides 350x more DTU Compute power than a basic database with 5 DTUs.

For existing Azure SQL Database workload, you can use SQL database Query performance insight to understand your database resource consumption to get deeper insight to understand your database resource consumption (DTUs). You can also use sys.dm_db_resource_stats DMV to get the resource consumption information for the last one hour. Also can use sys.resource_stats for last 14 days.



Elastic Database Transaction Units (eDTUs)
If there are more than 1 database and uses of these Database are different then Microsoft has option to share the resources between these databases. Elastic pool is an option on SQL Database Server that shares a pool of resources among those database. The shared resources in an elastic pool measured by elastic Database Transaction Units or eDTUs.

Powershell to create Elastic pool
Powershell parameters
$Location='Southeast Asia'
$ResourceGroupName='RG'
$SQLServerName='sql-server'
$DBName ='SQLDB1'
$EPoolName='SQLEpool'
$AdminLogin ='XXXXX'
$AdminPassword ='xxxxxxxxx'
$StartIP='219.91.0.0'
$EndIP='219.91.255.255'

First of all login to Azure subscription
 #********** Login to Azure account **********

Login-AzureRmAccount
Select-AzureRmSubscription -SubscriptionName '<<Your Azure Subscription Name>>'


# Create new Elastic pool
$EPool = New-AzureRmSqlElasticPool -ResourceGroupName $ResourceGroupName `
    -ServerName $SQLServerName `
    -ElasticPoolName $EPoolName `
    -Edition "Standard" `
    -Dtu 50 `
    -DatabaseDtuMin 10 `

# Move the database to the  pool
$Database = Set-AzureRmSqlDatabase -ResourceGroupName $ResourceGroupName `
    -ServerName $SQLServerName `
    -DatabaseName $DBName `
    -ElasticPoolName $EPoolName