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