Wednesday, January 18, 2012

Best site for EBook downloads for .Net

http://www.ebookee.biz/mcpd-70-519-exam-ref-designing-and-developing-web-applications-using-microsoft-net-framework-4.html#more-2242

Elmah (Error Logging Modules and Handlers)

Once we download a and register in our webapplication bin folder we can see our error log in Elmah.axd


Refer:this below link for indepth detail

 http://www.hanselman.com/blog/ELMAHErrorLoggingModulesAndHandlersForASPNETAndMVCToo.aspx

SqlServer 2012(Denali) New Features

http://www.sqlservergeeks.com/articles/sql-server-bi/80/new-built-in-functions-in-sql-server-2012-denali

 

1:FORCESEEK hint is extended to specify columns used to seek in the specified index

When SQL Server chooses seek over scan while retrieving record details, it will compare key value with search input, based on comparison result, Query engine will move to appropriate page. Suppose, index has multiple columns, if we don't want all key columns to consider, in SQL Server 2012, we can mention the index columns to consider when the index has multiple key columns. .

SELECT CompanyID,CompanyName,Amount
FROM COMPANIES
WITH (FORCESEEK(Idx_Company(CompanyID)))
WHERE CompanyID = 1
 

 2:FORCESCAN Hint added to force query optimizer to choose scan over seek

 

Often while tuning stored procedures, we will see tables have the "seek" operator. Few times one of reason for slow performance is wrong estimates on number of rows. Because of that, there are more chances that query optimizer choose "SEEK" over "SCAN". To force optimizer to choose "SCAN" over "SEEK", FORCESCAN hint has been added.

Select OH.OrderID,OD.ItemName,OH.OrderCost
from OrderHeader OH
INNER JOIN OrderDetails OD WITH (FORCESCAN)
on OH.OrderID = OD.OrderID
 
 3:OVER Clause is enhanced to apply aggregate functions while applying "Order By"
 
Before SQL Server 2012, We can't use "Order By" clause, while we are using aggregate functions in OVER clause. Suppose, to calculate company-wise cumulative revenues per year, we can't take the advantage of aggregate operators with OVER clause.
Below syntax is invalid before SQL Server 2012.

SUM(Amount) OVER (PARTITION BY CompanyID ORDER BY Year)
 
4:PERCENT_RANK()
 
PERCENT_RANK() function will returns the percentage value of rank of the element among its group.
PERCENT_RANK() function value will be
  1. For first element in its group, it will be 0.
  2. For last element in its group, it will be 1.
  3. For remaining elements, it will be ( No. Of Elements Before that Element ) / (Total Elements - 1)

.Net code for EXCEL

.NET code for Excel Border setting 

 Excel.Border topBdr=range.Borders[Excel.XlBordersIndex.xlEdgeTop];
Excel.Border bottomBdr=range.Borders[Excel.XlBordersIndex.xlEdgeBottom];
Excel.Border leftBdr=range.Borders[Excel.XlBordersIndex.xlEdgeLeft];
Excel.Border rightBdr=range.Borders[Excel.XlBordersIndex.xlEdgeRight];

topBdr=Excel.XlLineStyle.xlContinuous;

bottomBdr=Excel.XlLineStyle.xlContinuous;
leftBdr=Excel.XlLineStyle.xlContinuous;
rightBdr=Excel.XlLineStyle.xlContinuous;

 

.NET code for Alignment in Excel 

h1.HorizontalAlignment=Excel.XlHAlign.xlHAlignLeft;

Java Script Debugger in Internet Explorer 8

When Internet Explorer 8 is installed, built-in Java Script debugger ships along. Since this is an in-proc debugger one need not launch a separate app
It has all the familiar Visual Studio 2008 Features debugger like call stacks, watches, locals and immediate window
To get to the debugger just press SHIFT+F12, or click the developer tools icon in the command bar.
After launching the Developer Tools, switch to the script tab
 

Exampl to create autogenerated code verification

Create a page with name “Captcha.aspx”


   1: IMG height="30" alt="" src=BuildCaptcha.aspx width="80">


   2: asp:TextBox runat="Server" ID="txtCaptcha">


   3: <asp:Button runat="Server" ID="btnSubmit" 


   4:            OnClick="btnSubmit_Click" 


   5:            Text="Submit" />


   6:  


   7: 3. On “btnSubmit_Click” place the following code


   8:  


   9: if (Page.IsValid && (txtCaptcha.Text.ToString() == 


  10:      Session["RandomStr"].ToString()))


  11: {


  12:   Response.Write("Code verification Successful");


  13: }


  14: else


  15: {


  16:   Response.Write( "Please enter info correctly");


  17: }
Create one more page with BuildCaptcha.aspx
 
   1: Bitmap objBMP = new Bitmap(60, 20);


   2: Graphics objGraphics = Graphics.FromImage(objBMP);


   3: objGraphics.Clear(Color.Wheat);


   4: objGraphics.TextRenderingHint = TextRenderingHint.AntiAlias;


   5:  


   6:  


   7: //' Configure font to use for text


   8: Font objFont = new Font("Arial", 8, FontStyle.Italic);


   9: string randomStr = "";


  10: char[] myArray = new char[5];


  11: int x;


  12:  


  13: //That is to create the random # and add it to our string


  14: Random autoRand = new Random();


  15: for (x = 0; x < 5; x++)


  16: {


  17:   myArray[x] = System.Convert.ToChar(autoRand.Next(65,90));


  18:   randomStr += (myArray[x].ToString());


  19: }


  20:  


  21: //This is to add the string to session, to be compared later


  22: Session.Add("RandomStr", randomStr);


  23:  


  24: //' Write out the text


  25: objGraphics.DrawString(randomStr, objFont, Brushes.Red, 3, 3);


  26:  


  27: //' Set the content type and return the image


  28: Response.ContentType = "image/GIF";


  29: objBMP.Save(Response.OutputStream, ImageFormat.Gif);


  30: objFont.Dispose();


  31: objGraphics.Dispose();


  32: objBMP.Dispose();


  


 

AssemblyKeyFile could not be found ERROR

ERROR:
1. The type or namespace name 'AssemblyKeyFileAttribute' could not be found (are you missing a using directive or an assembly reference?)

2. The type or namespace name 'AssemblyKeyFile' could not be found (are you missing a using directive or an assembly reference?) 


Just include "System.Reflection" namespace. It resolve above two errors.

To associate an assembly with a strong key file to store it to GAC, we use should include following line after all the imports and before defing namespace.
For VB.NET:  <Assembly: AssemblyKeyFile("c:\path\mykey.snk")>
For C#:    [assembly: AssemblyKeyFile(@"c:\path\mykey.snk")]