Thursday, December 11, 2014

How to recursively remove a file type under a folder using PowerShell?


The below PowerShell code will help you to recursively find the files from a folder and remove it

The second line will recursively make the files in folder not rad only


$checkoutLocation = "D:\Develop\VSS\Vb"
# Removed the file recursively
Get-ChildItem -Path $checkoutLocation -Filter *.scc -Recurse | Remove-Item -Force

# Makes file not read-only recursively
Get-ChildItem -Path $checkoutLocation -Recurse | ForEach-Object { if ($_.IsReadOnly) { $_.IsReadOnly = $false } }

Monday, November 24, 2014

Why SQL server some times silently truncate the values you passed to a column and some time errors

Scenario

There are scenarios when SQL server silently truncate the values you passed to a column and sometime error as below. Actually what is happening behind the seen here?

Msg 8152, Level 16, State 14, Line 2
String or binary data would be truncated.
The statement has been terminated.

Let’s explore…….

The magic here is because of ANSI_WARNINGS begin set to OFF

In normal circumstances SQL server will truncate the data passed with respect to the underlying column if ANSI_WARNINGS is set to OFF. In case of ANSI_WARNINGS set to ON will result in the above error.

But this is overridden in case you are passing data through a variable. For example assume you have an underlying column of varchar(50) and you declare a variable varchar(50). If you try to assign the variable with a string having length greater than 50 then SQL server will automatically truncate the same to 50 with without popping any error irrespective of ANSI_WARNINGS OFF or ON.

But the above can result in an error if you are declaring the variable as varchar (40) for underling varchar (50) column.

Note: This truncation can also happen in .net before hitting to SQL server if you have explicitly declared the size of SQL parameter

For example:
comm.Parameters.Add("@Name", System.Data.SqlDbType.NVarChar, 50);
comm.Parameters["@Name"].Value = Name;

Sunday, November 9, 2014

Tech Ed 2014 Day 1 /2 Update on Best Practice on Azure Migration

Last week I got a chance to attend Microsoft Tech Ed 2014  @ Ashok Lalith. Bangalore

Thought of putting up the Best Practices which Microsoft suggests when moving existing Apps to Azure
 
Best Practice on Azure

Migration.

•Lift and shift- will not work and testing is required
•I am here today and will on cloud tomorrow, will not be happened
•Go for a Workload based approach

Steps for moving.

Don’t move your existing app suddenly, as a first step choose a least critical app and follow the below order
1. ISAAS – start as VM
2. Make it PAAS enabled -
3. Make it Service enabled

Best Practice

•Keep separate subscription for different type of VM..E.g. one for DEV test and other Live.

•The maximum IOPS we can get is 500 hence Create separate disks. For example in SQL create log files, data files etc. in separate disks.

•Don’t store anything on temp disk.

•Use azcopy for copying data to between.

•Enable Geo Replication…
http://azure.microsoft.com/blog/2014/09/03/azure-sql-database-standard-geo-replication/

•Locate a nearest storage location for you app... If your app is in India choose a storage location from India (Microsoft will be opening a datacentre for Azure in India soon).

•Never keep one VM in an availability set .

•Configure VM to start all service on reboot .

•Cloud Service in a subscription is limited to 200 .

•Use Wcat - to create test load on websites.
 

Tech Ed India 2014 Day 1 /2 Update Redis Cache

Last week I got a chance to attend Microsoft Tech Ed 2014  @ Ashok Lalith. Bangalore
Thought of putting up the new feature Microsoft has for Azure/.net on Redis Cache.

Redis Cache in .Net and Azure

  • Redis is an open source, BSD licensed, advanced key-value cache and store. It is often referred to as a data struc­ture server since keys can con­tain strings, hashes, lists, sets, sorted sets, bitmaps and hyperloglogs



  • It’s a Low latency, high through­put key value store
 

Tech Ed India 2014 Day 1 /2 Update on Visual Stu­dio 2013

Last week I got a chance to attend Microsoft Tech Ed 2014  @ Ashok Lalith. Bangalore

Thought of putting up the new feature Microsoft has for Visual Stu­dio 2013 which I got from Tech Ed
Asp.et MVC-Latest and Great­est so far on Visual Stu­dio 2013
  • One ASP.NET in Visual Stu­dio 2013 — A New Uni­fied Project Sys­tem for Web Devel­op­ers.

  • Work­ing with mul­ti­ple frame­works in a sin­gle project is made sig­nif­i­cantly eas­ier, enabling devel­op­ers to com­bine Web Forms, MVC, Web API and other project tem­plates together using an enhanced new project dia­log. Avail­able from visual stu­dio 2013 with Asp, net >5

  • No need of SQL express.




 

Tech Ed India 2014 Day 1 /2 Update on Asp.net vNext

Last week I got a chance to attend Microsoft Tech Ed 2014  @ Ashok Lalith. Bangalore

Thought of putting up the new feature Microsoft has for Asp.net vNext which I got from Tech Ed

Asp.net vNext ---The next generation
  • Totally Mod­u­lar.
  • Inter­de­pen­dency between unnec­es­sary dll’s being avoided. Means No more System.Web !!!.
  • Frame­work goes along with the appli­ca­tion (means can be shipped with the app).
  • Save and Refresh, no Build.
  • Works on cross plat­form (using mono)
  • No depen­dency on Visual stu­dio (can use other com­pat­i­ble Editors/Tools of your choice like notepad++ etc.).
  • Improve­ment in start-up time.
  • Faster deploy­ment Cycle.
  • Is back­ward compatible.
  • No web.config.Web.config has trans­formed to project.json. Intel­li­gence avail­able in JSON.
  • No global.ascx.
  • Startup.cs becomes the entry point.
  • Ref­er­ence are no more and replaced with nugget pack­ages and man­aged in local user folder.
  • No more dll in bin/debug folder on run­ning as the same is man­aged in mem­ory (magic of for new Roslyn compiler).
  • ASP .net 5.0. is the desk­top full ver­sion of CLR and ASP.net core 5 is the cloud opti­mized ver­sion of CLR.
  • No project reference…need to added to the projecy.json.
  • “Pro­duce Out­put dur­ing build” on project prop­erty will pro­duce a nugget pack­age which can be used for other project ref­er­ence. The same has to be copied to the local nugget pack­age repos­i­tory for other project to refer.
  • The magic “K”..no need of IIS, the app can be run on any plat­form. OWIN, the Open Web  Inter­face for .NET is tak­ing over the ASP.NET run­time.
  • http://developer.telerik.com/featured/microsofts-special-k-an-introduction-to-asp-net-vnext/
  • The source code of Asp.net Vnext is open and avail­able on github.
  • Microsoft’s new strat­egy is… mobile-first, cloud-first”.
  • Save and Refresh, no Build
  • More Read­ing @ http://www.hanselman.com/blog/IntroducingASPNETVNext.aspx
 

Tech Ed 2014 Day 1 /2 Update on Azure - New features comming up in Azure

Last week I got a chance to attend Microsoft Tech Ed 2014  @ Ashok Lalith. Bangalore

Thought of putting up the new feature Microsoft has for Azure which I got from Tech Ed

Azure New Features

In build load balancer
http://msdn.microsoft.com/en-us/library/azure/dn655058.aspx

Azure services monitoring with– SCOM (System Centre Management Pack for Windows Azure)
http://slvirtualguy.com/2014/03/23/azure-services-monitoring-with-scom-2012-r2/

Manage the availability of virtual machines using Availability set
http://azure.microsoft.com/en-in/documentation/articles/virtual-machines-manage-availability/

Regional Virtual Networks
http://azure.microsoft.com/blog/2014/05/14/regional-virtual-networks/
http://windowsitpro.com/azure/understand-regional-networks-azure

Virtual Network – uses to connect DB files, apps hosted in premises
http://azure.microsoft.com/en-us/services/virtual-network/

Web Jobs - Complete compute solution on a managed platform
http://www.hanselman.com/blog/IntroducingWindowsAzureWebJobs.aspx

Azure Resource Management
Resource groups - logical grouping of all resources used in a project /app
http://azure.microsoft.com/en-us/documentation/articles/azure-preview-portal-using-resource-groups/

Mobile push notification to any client with Azure Notification hub
http://azure.microsoft.com/en-us/documentation/services/mobile-services/

A new portal for Azure   https://portal.azure.com

A new breed of Developers coming … Dev Ops  (not an Azure feature )
http://en.wikipedia.org/wiki/DevOps

Application Insight – for monitoring the health of application
http://msdn.microsoft.com/en-us/library/dn481103.aspx

Ability to group billing usage and forecast
http://azure.microsoft.com/en-in/support/understand-your-bill/

RBAC – Role based access control
http://azure.microsoft.com/en-us/documentation/articles/role-based-access-control-configure/

Azure Resource Manager Tools for Visual Studio - Advanced Template Editing using JSON
http://blogs.msdn.com/b/rmattsampson/archive/2014/08/19/azure-resource-manager-tools-for-visual-studio.aspx
 

Thursday, June 12, 2014

How to check SQL server collation?

For checking database collation you can sue the below command

select serverproperty('collation')


select databasepropertyex('master','collation')

Thursday, May 22, 2014

Javascript to detect whether user is viewing the page

Today I was writing a javascript to check whether there is a user activity on the page or not. Thought of putting the same to blog so that some on else can use of it.

Here is the code for it......

<script src="~/Scripts/jquery-2.1.1.min.js"></script>
<script>
    //Assinging the setInterval for function time()  for every 1 seconds, used to show time
    var myVar = setInterval(function () { time() }, 1000);
    //assinging the setInterval for function reset() for every 5 seconds, used to reload page
    var myVarReset = setInterval(function () { reset() }, 5000);
   
    //Function to show the time and will be update in nevery second
    function time() {
        var d = new Date();
        var t = d.toLocaleTimeString();
        $('#time').text(t);
    }

    //Function to reload the page which is set to call every 5 seconds using  setInterval
    function reset()
    {
        location.reload();
        alert("Reset");
    }
    //Handling the onmousemove event of the form
    window.onmousemove=function()
    {
        //clering the setInterval for function reset()
        clearInterval(myVarReset);
        //Againg assinging the setInterval for function reset()  for every 5 seconds
        myVarReset = setInterval(function () { reset() }, 5000);
    }
</script>
<text id="time"></text>

So how does this code works?

First of all we need to understand what does setInterval and clearInterval does?

The setInterval() method calls a function or evaluates an expression at specified intervals (in milliseconds).
The setInterval() method will continue calling the function until clearInterval() is called, or the window is closed.
The ID value returned by setInterval() is used as the parameter for the clearInterval() method.
Tip: 1000 ms = 1 second.

Tip: To execute a function only once, after a specified number of milliseconds, use the setTimeout() method.

Let’s look into the  ode in detail……………….

    var myVar = setInterval(function () { time() }, 1000);
    var myVarReset = setInterval(function () { reset() }, 5000);
In this part we are using setInterval to set two functions “time” and “reset”, one for showing the current time on the page and the other for reloading the page if there is no user activity for 5 seconds. The output of these factions are assigned to variable myVar and myVarReset respectively.

    function time() {
        var d = new Date();
        var t = d.toLocaleTimeString();
        $('#time').text(t);
    }
This part is responsible to show the current time on the page , which will be called every 1 second  as defined by the above setInterval

    function reset()
    {
        location.reload();
        alert("Reset");
    }
This function just reloads the page

    window.onmousemove=function()
    {
        clearInterval(myVarReset);
        myVarReset = setInterval(function () { reset() }, 5000);
    }

Here we handle the onmousemove on the page and resets the setinterval for reset() function using the clearInterval by passing variable myVarReset.

Once it is reset , the function reset() is again set to call eve very 5 seconds using setInterval.


Friday, May 16, 2014

PowerShell script for listing folders in a location with their last Accessed date and size

Today I was asked to write a power shell function for listing the folders in a location with their last Accessed date and size. Thought of sharing the same so that someone else can make use of it.

I just wrote this as function so that it can reused easily. This function give the result in excel


Function Get-FolderSize
{
 Param(
         [Parameter(Mandatory=$true)]
         [string]$loactaion
        )#end param

# Adding to Excell Sheet

$strComputer = “.”
$Excel = New-Object -Com Excel.Application
$Excel.visible = $True

$Excel = $Excel.Workbooks.Add()
$Sheet = $Excel.WorkSheets.Item(1)
$Sheet.Cells.Item(1,1) = “Folder”
$Sheet.Cells.Item(1,2) = “Last Accessed”
$Sheet.Cells.Item(1,3) = “size”

$WorkBook = $Sheet.UsedRange
$WorkBook.Interior.ColorIndex = 8
$WorkBook.Font.ColorIndex = 11
$WorkBook.Font.Bold = $True
$intRow = 2


$colItems = Get-ChildItem  $loactaion -recurse | Where-Object {$_.PSIsContainer  }

foreach ($i in $colItems)
{
     $kk = Get-ChildItem  $i.FullName -recurse | Measure-Object -property length -sum
     $Sheet.Cells.Item($intRow,1) = $i.FullName
     $Sheet.Cells.Item($intRow,2) = $i.LastAccessTime
     $Sheet.Cells.Item($intRow,3) = "{0:N2}" -f ($kk.Sum / 1MB) + "MB"
     $intRow = $intRow + 1
}

$WorkBook.EntireColumn.AutoFit()
}


Usage

Get-FolderSize "D:\yourfolder" 

Wednesday, May 14, 2014

Add support for the scroll wheel to the Microsoft Visual Basic for Applications 6 environment

The Classic VB IDE was actually written before the mouse wheel was invented, believe it or not. There have been numerous tools and assorted hacks offered over the years to remedy the native non-support VB provides, but I've found the below more interesting.

Please follow the steps in below page to configure scrolling in VB6 IDE.