Tuesday 28 June 2016

Asynchronous programming with Async and Await

Let we see the simple implementation of async and await opertor in C# code.

1. Always async should be mention in method after access specifier.
2. Method name should be end in async.
3. Return type of async method be in void, Task, Task<T>



                The first thing is to know is that any method that you put async in front of is an asynchronous method, which means it can be started and stopped rather than just run from first to last instruction. We could create a new method and mark is as asynchronous but to keep the example as much like the synchronous case described above we can simply change the Click event handler into an asynchronous method:

private async void button1_Click(object sender, RoutedEventArgs e)
      {
         label1..Text = "Started";
         DoWork();
  label2.Text = "Finished";
      }

private int DoWork()
{
 return 1+2;
}



Now the compiler will say a message as Asynchronous method with not Await, make to run the method in synchronous way, So i have added await keyword in calling a method.

                  private async void button1_Click(object sender, RoutedEventArgs e)
    {
               label1..Text = "Started";
                await DoWork();
        label2.Text = "Finished";
          }

private int DoWork()
{
 return 1+2;
}

Now compiler will say a message that you can't await a method that returns void. we have to change the return type as Task or Task<T>.Now let we see the Task 




What is Task ?
    Task is an object that runs the code in separate thread from the UI thread which release the UI to do some other work.

Now we see the implemetation of await with task return type

              private async void button1_Click(object sender, RoutedEventArgs e)
              {
                    label1..Text = "Started";
                   await Task.Run(()=> DoWork());
                    label2.Text = "Finished";
              }

             private int DoWork()
             {
                 return 1+2;
             }




From this article I hope you will understand the async and await operation clearly when comparing to synchronous operation, and learn to change a call sync method to await call of Task return type method.








Sunday 26 June 2016

Information about Hedge Funds

In this post we are going to see what is a "Hedge Funds" in Investors world, and how it is differ from other 
Fund systems.

Hedge Funds are the normally named as “Alternative Investments” using pooled Funds. Hedge Funds uses different
strategies to yield a “Active Return” or “Absolute Return” for their investors. 

Hedge Fund are usually used by Wealthy individuals or Institutions, They used a aggressive strategies that are 
unavailable in Mutual Funds including Selling Shot, Leverage, Trading, arbitrage and derivatives Hedge Funds are restricted by law No more than 100 or 500 investors by Fund. 






Hedge Funds are the funds where highly wealthy people are allowed to invest, they are consider as investors because each and every investments are in 1 Million $. Each hedge fund follows a strategy is Constructed to take advantage of certain identifiable market opportunities. Hedge funds use different investment strategies and thus are often 
classified according to investment style. 

There is substantial diversity in risk attributes and investment opportunities among styles, which reflects the flexibility of the hedge fund format. In general, this diversity benefits investors by increasing the range of choices among investment attributes.





Hedge Funds main target is generating positive returns in Both up and Down markets. Through out the time investors are looking for ways to maximize the profit and minimizing the Risks. Shielding an investment from market 
risk through a alternate investment is called as “Hedge Funds”.




Always Absolute return is the term is used along with Hedge Funds, this describes that there will be a active return will be for investors in Good and Bad markets. 

“More sophisticated individuals or institutions are the investors in these kind of Hedge Funds”, A investor must pass an “Accredited investor test or qualifier purchase test“ whose net worth exceeds 1$ million or whose income in the 
last year $200,000 , there also another entity asses exceeds 5$ Million.

Hedge Funds rely on sections 3 (c)(1), and 3 (c)(7) of the investment company act of 1940 , Hedge funds are 
prohibited from advertising there funds from Public. 





Hedge Fund Managers are applying strategies they will add alpha ,they will use there skill to solve the inefficiency
in the market. Hedge Funds concentrate on the Active or absolute returns for their investors

Hedge Funds try to protect their investors in the downside of the market , an Hedge Funds portfolio have lot of 
investments where investors can choose there hedge funds based on the sophistication 




From this post you can learn some basic information about the Hedge Funds and there advantages to the investors




Thursday 23 June 2016

Question and Answers in Sql Server - Part 20

In This post Let we see some important question and answers in Sql Server, which is a continuation of previous post.

70. what are the various options of recovery model  ?

          Full, Bulk-logged, Simple
         
          Full : No work is lost, due to failure. It is default recovery model.

          Bulk-logged : Allows high-performance bulk copy operations. Minimum space    
                               is required , we can perform recovery when have taken the     
                                  backup of the database.

          Simple: Allows high-performance bulk copy operations,  we can perform  
                        recovery when we have taken the backup,advantage of using this is  
                        minimumspace requirement.


71. How to back-up database?

1.     Right click the database,Select Tasks in that select Back up database.

2.     Select the General in the left pane.

3.     Select the database to back up.

4.     Select a Back up type.
Full: Used for database , files, and filegroups.
Differential : Used for capture all data’s that has changed since the last full database backup.
Transaction log: Capture the modifications to the database, provide the history of the transaction takes place in the database.
Select the Full option.

5.     Select “Database” in back up component group.

6.     Give the name of the backup database.

7.     Select the Disk in the destination back up type and click ok.




I hope from this series of questions and explanation will give a basics and intermediate things in SQL SERVER. This articles make you to understand the about SQLSERVER.

Question and Answers in Sql Server - Part 19

In This post Let we see some important question and answers in Sql Server, which is a continuation of previous post.


69. Create a User in SQL SERVER?
          Users can be created in Server level as well as database level. Now we see Steps to create the new user in server level.

1.     Right click the Security and click New and Select Login.

2.     Now a screen launches and select in General tab.

3.     Give the name for the Login Name

4.     Select Sql Server authentication and give password and new password.

5.     Uncheck the “user must change password at next login.”

6.     Select the Default Database from the database list.

7.     Now select the Server Roles from the left pane.

Server roles are the roles assign to the user to allow the user to do the actions in the server level based on the privileges,

Bulkadmin : allow user to execute the bulk insert statement in DB.

dbcreator : allow user to create the DB

diskadmin: allow user to do the manage disk files.

process admin: allow user to kill the process

public : every user is mapped to public user.

securityadmin : allow user to do the action of grant and deny permission

serveradmin: allow user to do the server wide configuration

setupadmin: allow user to do the setup like linked server

sysadmin: allow user to do all actions in server


8.     Now select the all list from the server roles

9.     Select the “User Mapping” from the left pane. In that we can map a user access to the database and schema.

10. Map the Database and see now and list of database role will seen under the map database panel.

11. Database Role Membership Which gives or specifies the roles to the user for that particular database

Public: this is the default role mapped to the user in db.

db_accessadmin: can able to add or remove access for windows login users.

db_backupoperator: can able to backup the db

db_datareader: can able to do read the data

db_datawriter: can able to do all add, delete and modify the data

db_ddladmin: can able to do all data definition language

db_owner: can able to do configuration and maintenance

db_denydatareader: can’t able to read data.

db_denydatawriter: can’t able to add,delete and modify data.

db_securityadmin: able to add role and manage permissions.



12. Now select the db_owner,db_datareader,db_datawriter,db_ddladmin, public

13. Now select the Securables  in the left pane and click search and add the object and give the give the permission on the list.

14. Now select the status in the left pane and select the Grant in the permission to connect to database engine and select enabled in login.





Question and Answers in Sql Server - Part 18

In This post Let we see some important question and answers in Sql Server, which is a continuation of previous post.



67. How To CREATE Policy Based Management ?

      In Our example we are going to create a policy that function that create in db must be starts with name udf_.

       step 1. expand the Policy Based Management      

       step 2. Right click Condition and create a new condition

       step 3. specify the condition name and select facet as UserDefiendFunction as our sample 

       step 4: In the grid sepcify the Attribute 
                   Field : @Name
                   Operator: Like
                    Value : 'UDF_%'

      Step 5: click Ok.

      Step 6. Right Click the Policy and create a new Policy

      Step 7: Give a name for the policy and select the condition present in combo and select Evaluation                             Mode: Change:Prevent

      Step 8: Enable the Policy and Click Ok.



68. What is Change Tracking ?

       Change Tracking is used to track the changes takes place in the tables with in the database. to read about Change Tracking Click Here to read about Change Tracking





Question and Answers in Sql Server - Part 17

In This post Let we see some important question and answers in Sql Server, which is a continuation of previous post.

65. What is E-R Diagram ?
       An E-R Diagram is a graphical representation of  the inter relationship between the Entities in a database. Table is an Entity  ex: Employee table is an Entity

      An E-R Diagram Consists of an Following Elements.
      1. Entities      [Table   i.e Employee]  
      2. Attributes  [Columns i.e Employeeid,Name,Salary]
      3. Relationships [relationship between two tables]  , i.e three types One-One,One-Many,Many-Many


       One-One :  Person table - Passport table
       One - Many : Student - Subjects
       Many - Many : Customer - Order



66. What is Policy Based Management [PBM] ?
      Policy Based Management is a new feature in SQL Server 2008 that enables database administrators to  create and enforce policies to configure and manage SQL SERVER. A policy is a Rule that specifies a certain conditions to be evaluated against a managed Target.

       Following are the basic terms in PBM
      1. Managed Target
      2. Facet
      3. Condition
      4. Policy
      5. Policy Category
      6. Effective Policy


     Managed Target : A Managed Target is an Entity on which you want to apply policy. Ex Sql Server instance, Schema, Database etc.
     

     Facet :  Facet is set of properties that model the behavior and characteristics of a managed target.


    Condition : A condition is a one or more clauses that specify properties of a facet.
  

    Policy : A Policy contains the condition that specifies how to set the properties of the facet of a managed target.


    Policy Category : we can group the policy into different policy types known as policy categories.A policy can be belong to only one category. we can create policy categories at server level or database level.
   

    Effective Policy :  A Policy is considered to be effective policy if:
     1. Policy is Enabled
     2. The managed target belongs to the set of managed targets targeted by the policy.
     3. The managed target or one of its ancestors subscribes to the policy category that contains the policy.




Question and Answers in Sql Server - Part 16


In This post Let we see some important question and answers in Sql Server, which is a continuation of previous post.

61.  Usage of GoTo statement?
            Goto statement causes the program control to unconditionally jump to the label specified in the GOTO statement.
           

DECLARE @i INT =1
WHILE(@i < 8)
BEGIN

      IF @i%4=0
      GOTO outofloop;
      ELSE
      GOTO Incr;

      Outofloop:
      BREAK;

      Incr:
      PRINT @i
      SELECT @i+=1

END

Output:
1
2
3



62.  What is ACID?
            ACID is an acronym of four important properties i.e Atomicity, Consistency, Isolation and Durability.

o   Atomicity
It ensures that any update occurs in the database, then either all or none of the transactions executed successfully.

o   Consistency
It ensures that any changes update in the database is consistent and logical after and before of the update committed successfully.

o   Isolation
It ensures that multiple transactions are executed simultaneously, Then each Transaction is isolated from each other till the transaction executed completely.

o   Durability
It ensures that the data will be restored when system crashes or power failure up to last committed successful transaction. Durability ensures that the data is permanent after updating.


63.  What is partition? How it is helpful in improving the performance?
            After index a table we can further optimize the performance of a table by partitioning the tables and indexes. Partitioning allows you to modify the data without affecting the integrity of the entire collection. Partition is the process of distributing the data of tables and indexes on separate filegroups.

       Need to perform the following task to create the partition
o   Create a Partition Function
o   Create File groups
o   Create a Partition Scheme
o   Create a Partition Table


-- Create a Partition Function [function takes one parameter as input]
CREATE PARTITION FUNCTION emp_partfunc(INT)
AS RANGE LEFT        --Left keyword specifies that vlaues one less than the specified
FOR VALUES(1980,1990,2000,2010)


-- Create a File group
RIGHT Click ON DATABASE
CLICK Properties AND SELECT FileGroups AND ADD four GROUP f1,f2,f3,f4


-- Create a Partition Scheme
CREATE PARTITION SCHEME emp_part_sch
AS PARTITION emp_partfunc
TO (f1,f2,f3,f4)


-- Create a partition table
CREATE TABLE employ(id INT IDENTITY(1,1), NAME VARCHAR(40),yearofjoin INT)
ON emp_part_sch(yearofjoin)



64.  Resource Governance
            SQL Server provides a new feature known as Resource Governor, which allows the database administrators to put a check on the server resources consumed by various connections or applications. It can control the CPU time and memory used by specific applications. It allows you to allocate the server resources to different types of connections. It category the incoming connections to different workloads groups, Each of which can be monitored individually. WorkLoad group are contained inside the resource pool which contains the portion of CPU and memory resources available to the current instance. It allows you to set importance for different workload groups.

o   Creating a Resource Pool
o   Creating a workload group
o   Creating a classifier function
o   Configure the Resource governor.


-- Create a Resource Pool
CREATE RESOURCE POOL reportpool
WITH (MAX_CPU_PERCENT = 50, MAX_MEMORY_PERCENT = 50)


-- Create a WorkLoad Group
CREATE WORKLOAD GROUP reportworkload
WITH (IMPORTANCE = HIGH)
USING samplepool


-- Create a Classifier Function
CREATE FUNCTION reportfunc()
RETURNS sysname
WITH schemabinding
AS
BEGIN

   DECLARE @wklgrp sysname
   IF(APP_NAME()= 'Report application')
   SET @wklgrp = 'reportworkload'
   ELSE
   RETURN default
  
   RETURN @wklgrp
END


-- Classifier the Resource Governer
ALTER RESOURCE GOVERNOR
WITH ( CLASSIFIER_FUNCTION = dbo.reportfunc)
GO

ALTER RESOURCE GOVERNOR RECONFIGURE

GO