Friday, January 31, 2014

Differences Between IsNull() and Coalesce() Functions.



1. The COALESCE() function is based on the ANSI SQL standard whereas ISNULL function is a Transact-SQL function.

2. An expression involving ISNULL with non-null parameters is considered to be NOT NULL, while expressions involving COALESCE with non-null parameters is considered to be NULL.


Example
SELECT COALESCE(NULL, NULL) --error

SELECT ISNULL(NULL, NULL) --correct

3. The ISNULL() function contains only two parameters. The COALESCE() function contains multiple parameters.

If we use more than two parameters with the ISNULL function then we must use nested ISNULL functions.


Example
SELECT COALESCE(NULL, NULL, 'Hello') --correct

SELECT ISNULL(NULL, NULL, 'Hello') --error

4. The ISNULL() function looks at the first value and the second parameter value is automatically limited to that length but COALESCE() does not have this restriction.

Example
declare @test varchar(3)

select isnull(@test, 'ABCD') AS ISNULLResult ---output ABC

select coalesce(@test, 'ABCD') AS coalesceResult ---output ABCD

5. The ISNULL() function contains various types of parameters. The COALESCE() function doesnt limit the number of arguments,but they must all be of the same data type.


Example
DECLARE @a VARCHAR(5)='Hello', @b INT =5

SELECT ISNULL(@a, @b) AS ISNULLResult-- ok

SELECT COALESCE(@a, @b) AS COALESCEResult-- wrong Conversion failed when converting the varchar value 'Hello' to data type int.














difference between sql server 2008 and 2008r2.

1.SQL Server 2008 R2 will have editions that support up to 256 logical processors, an increase from the maximum support of 64 logical processors with past releases.
2.Master Data Services(MDS) part of BI solutions, people say it is introduced avoid data conflicts in DW, not sure how to implement it.
3.One more new feature in BI is Power Pivot, PowerPivot is designed to meet the more focused BI needs of end users through integration with Microsoft Excel and SharePoint.
4.SQL Server Reporting Services (SSRS): adds to previous geospatial data types by offering new visualization mapping capabilities for reports.
5.SQL Server Management Studio (SSMS): new dashboards to DBAs for monitoring and managing multiple instances of SQL Servers from a single screen, this functionality is not available in SQL Server express edition.

Diff Between 2005 & 2008 Sql server.


1XML datatype is introduced.XML datatype is used.
2Can not encrypt the entire database.Can encrypt the entire database introduced in 2008.
3Datetime is used for both date and time.Date and time are seperately used for date and time
4No table datatype is included.Table datatype introduced.
5SSIS is started using.SSIS avails in this version.
6CMS is not available.
Central Management Server(CMS) is Introduced.
7PBM is not available
Policy based management(PBM) server is Introduced.

Sunday, January 26, 2014

Bundling and Minification


Basically a developer uses multiple JS and CSS files for modularity, readability and maintainability of code and it’s a good practice too. But in some cases it leads to degradation of the overall performance of the website. Because multiple JS and CSS files require multiple HTTP requests from a browser leads to degrade the performance & load time of your web pages.

In real-time, almost every website uses
Minification technique to improving their load times, but bundling is not used commonly because every page required different sets of files and the application will also not support as much to make it simpler.

Bundling: It’s a simple logical group of files that could be referenced by unique name and being loaded with one HTTP requestor.

Minification: It’s a process of removing unnecessary whitespace, line break and comments from code to reduce its size thereby improving load times.

 

Bundling
Bundling is a new feature in ASP.NET 4.5 that makes it easy to combine or bundle multiple files into a single file. You can create CSS, JavaScript and other bundles. Fewer files means fewer HTTP requests and that can improve first page load  performance.

 

Minification

Minification performs a variety of different code optimizations to scripts or css, such as removing unnecessary white space and comments and shortening variable names to one character. Consider the following JavaScript function.

 

  BundleTable.EnableOptimizations = true;

 

Friday, January 24, 2014

How to know connection details in connection pooling in sql server?

SELECT
    DB_NAME(dbid) as DBName,
    COUNT(dbid) as NumberOfConnections,
    loginame as LoginName
FROM
    sys.sysprocesses
WHERE
    dbid > 0
GROUP BY
    dbid, loginame
;


also check  :
sp_who2 'Active'

How to manage multiple button on one page in mvc?

Model(Login.cs)




public class Login

{


[Required]

[Display(Name="UserName")]
public String UserName { get; set; }


[Required]

[DataType(DataType.Password)]

[Display(Name="Password")]
public string Password { get; set; }

internal bool IsValid(string p, string p_2)

{

if (p == "sahil")

return true;

else

return false;

}

}



Controller(Home)

public ActionResult Index()

{

return View();

}


[HttpPost]

[AllowAnonymous]
public ActionResult Index(Models.Login ln, string a)

{

if (a == "Submit")

{

if (ModelState.IsValid)

{

if (ln.IsValid(ln.UserName, ln.Password))

{

return RedirectToAction("Welcome", "Home");

}

else

{

ModelState.AddModelError("", "Login data is incorrect!");

}

}

return View(ln);

}

else { return RedirectToAction("Register", "Home"); }

}





View(index.cshtml)

@model MvcApplication1.Models.Login

@{ViewBag.Title = "Index";}

@using (Html.BeginForm())



{

@Html.AntiForgeryToken()

@Html.ValidationSummary(true, "Login failed. Check your login details.");

<fieldset >

<legend>Login </legend>

<div>

<div>

<div>@Html.LabelFor(m=>m.UserName)</div>

<div> @Html.TextBoxFor(m=>m.UserName)</div>

<div> @Html.ValidationMessageFor(m=>m.UserName)</div>

</div>

<div>

<div>@Html.LabelFor(m=>m.Password )</div>

<div> @Html.TextBoxFor(m => m.Password)</div>

<div> @Html.ValidationMessageFor(m => m.Password)</div>

</div>

<div>

<div><input type="submit" id="btnSubmit" name="a" value="Submit" />

<input type="submit" id="btnRegister" name="a" value="New User" /></div>

</div>

</div>










</fieldset>



}


How to bind Dropdownlist in mvc.

Home ontroller

public ActionResult Register()
{
ViewBag.stateList = getState(); 
return View();
}
[HttpPost]
public ActionResult Register( Models.Register rn, HomeController ddlListPostData)
{
if (ModelState.IsValid)
{
HomeController ddlList = new HomeController() { istateid = ddlListPostData.istateid };
}
ViewBag.stateList = getState();
return View(rn);
}

public virtual string istateid { get; set; }
public SelectList getState()
{
db_TestNewEntities _db = new db_TestNewEntities();
IEnumerable<SelectListItem> stateList = (from m in _db.tblCountry select m).AsEnumerable().Select(m => new SelectListItem()
{ Text = m.Name, Value = m.CountryID.ToString() });
return new SelectList(stateList, "Value", "Text", istateid);
}


Model (register.cs)
public class Register

{


[Required]

[Display(Name = "UserName")]
public String UserName { get; set; }


[Required]

[DataType(DataType.Password)]

[Display(Name = "Password")]
public string Password { get; set; }

internal bool IsValid(string p, string p_2)

{

if (p == "sahil")

return true;

else

return false;

}

}



View (Register.cshtml)

@model MvcApplication1.Models.Register

@{ ViewBag.Title = "Register";}

<h2>Register</h2>

@using (Html.BeginForm())




{
 
@Html.AntiForgeryToken()

@Html.ValidationSummary(true, "Login failed. Check your login details.");

<fieldset >

<legend>Login </legend>

<div>

<div>

<div>Country</div>

<div>@Html.DropDownList("istateid", (SelectList)ViewBag.stateList, "--Choose Your State--", new { id = "State" })</div>

<div> @Html.ValidationMessage("State", "*")</div>

</div>

<div>

<div>@Html.LabelFor(m=>m.UserName)</div>

<div> @Html.TextBoxFor(m=>m.UserName)</div>

<div> @Html.ValidationMessageFor(m=>m.UserName)</div>

</div>

<div>

<div>@Html.LabelFor(m=>m.Password )</div>

<div> @Html.TextBoxFor(m => m.Password)</div>

<div> @Html.ValidationMessageFor(m => m.Password)</div>

</div>

<div>

<div><input type="submit" id="btnSubmit" name="a" value="Submit" /> </div>

</div>

</div>

</fieldset>



}