Friday, January 27, 2012

SSRS Setup creation

Refer :

1:Download  RS Scripter Tool
http://www.sqldbatips.com/showarticle.asp?ID=62
2:http://weblogs.asp.net/akjoshi/archive/2009/01/29/using-rs-scripter-to-create-deployment-script-for-reporting-services.aspx


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")]
 

Tuesday, January 17, 2012

How to block the ASP.NET page while ajax UpdateProgress is being displayed

Write the css style :

<style type="text/css">
      .hide
      {
          display: none;
      }
      .show
      {
          display: inherit;
      }
       .progressBackgroundFilter
      {
          position: absolute;
          top: 0px;
          bottom: 0px;
          left: 0px;
          right: 0px;
          overflow: hidden;
          padding: 0;
          margin: 0;
          background-color: #000;
          filter: alpha(opacity=50);
          opacity: 0.5;
          z-index: 1000;
      }
      .processMessage
      {
          position: absolute;
          font-family:Verdana;
          font-size:12px;
          font-weight:normal;
          color:#000066;
          top: 30%;
          left: 43%;
          padding: 10px;
          width: 18%;
          z-index: 1001;
          background-color: #fff;
      }
  </style>

Design the Update progress as below :

<asp:UpdateProgress ID="updPrgsBaselineTab" runat="server">
       <ProgressTemplate>
           <div id="progressBackgroundFilter" class="progressBackgroundFilter">
           </div>
           <div id="processMessage" class="processMessage">
               <table width="100%">
                   <tr style="width: 100%">
                       <td style="width: 100%">
                           Please Wait..........
                       </td>
                   </tr>
                   <tr style="width: 100%">
                       <td style="width: 100%" align="center">
                           <img src="../Images/Update_Progress.gif" />
                       </td>
                   </tr>
               </table>
           </div>
       </ProgressTemplate>
   </asp:UpdateProgress>

Hibernate in XP & Code for Hibernate in Windows Application

Below are the steps to enable Hibernate in Windows XP

  1. Right click on Desktop.
  2. Click on properties.
  3. Go to screen save tab.
  4. Click on power button
  5. Select Hibernate tab
  6. Check the checkbox “Enabled Hibernate”
  7. Apply the settings. 

To provide this feature programatically in our .Net windows application



using System.Windows.Forms;

namespace CodeKicks.WinApp.Machine
{
    public static class MyMachineHelper
    {
        public static void DoHibernate()
        {
            //Application.SetSuspendState(PowerState.Suspend, true, false);
            Application.SetSuspendState(PowerState.Hibernate, true, false);
        }
    }
}

Code for adding images to a imagelist from a folder



Public Shared Function InitImageListFromDirectory(pDirectory As String) As ImageList
  Dim imageList As New ImageList()

  For Each f As String In System.IO.Directory.GetFiles(pDirectory)
    Try
      Dim img As Image = Image.FromFile(f)
      imageList.Images.Add(img)
        ' Out of Memory Exceptions are thrown in Image.FromFile if you pass in a non-image file.
    Catch
    End Try
  Next

  Return imageList
 End Function

Monday, January 9, 2012

Adding items to Listbox using threading


In VB.Net windows application ,there is a issue adding items to listbox while there is a timer control .

This issue can be resolved as below


 Private Delegate Sub UpdateListInvoker(ByVal StringList As List(Of String))

    Private Sub AddStatusLog(ByRef EventText As String)
        Dim i As Short

        If lstStatusLog.Items.Count > 30000 Then
            For i = 1 To 1000
                lstStatusLog.Items.RemoveAt(0)
            Next i
        End If

        Dim strval As String = VB6.Format(Now, "long time") & " " & EventText
        Dim nThread As New Threading.Thread(AddressOf TestList)

        nThread.Start(strval)

               sta.Items.Item(1).Text = EventText
    End Sub

    Private Sub TestList(ByVal EventText As Object)
        UpdateList(New List(Of String)(New String() {EventText}))
    End Sub

    Private Sub UpdateList(ByVal strList As List(Of String))
        If Me.lstStatusLog.InvokeRequired Then
            Me.lstStatusLog.Invoke(New UpdateListInvoker(AddressOf UpdateList), strList)
        Else
            Me.lstStatusLog.Items.AddRange(strList.ToArray)
        End If
    End Sub

Knowing u r sqlserver is 32 bit or 64 bit

  SELECT @@VERSION
If the version returned is x86 that means it is a 32 bit installation and if it is x64 then it means it is a 64 bit installation.

Wednesday, January 4, 2012

Free online books for Sql Certification

Refer :http://www.sqlserver-training.com/certification-resources/downloads

http://www.sqlserver-training.com/certification-resources

Monday, January 2, 2012

Visual Styles-related operation resulted in an error because no visual style is currently active

This issue will come when we developed a windows application in windows xp and trying to run ha in windows server os ,then it will not support that themes of windows classic .

To resolve this issue

1: Run->services.msc-->Themes-->Start(Automatic)
2:ControlPanel-->Display-->Appearance-->SelectWindows XP Theme.



Different Sql query for DateFormat

1:To convert 280908(ddmmyy) to 2008-09-28 00:00:00.000

 a- SELECT CONVERT(DATETIME, STUFF(STUFF('280908',3,0,'/'),6,0,'/'), 3)
 b- declare @tst Varchar(6)
     Set @tst = '280908'
     Select cast(substring(@tst,3,2) + '/' + left(@tst,2) + '/' + right(@tst,2) as datetime)


2:Number of weeks between two different dates

SQL :SELECT DATEDIFF (ww, '01/01/1753', '12/31/9999');  

ORACLE:SELECT floor(
             (to_date('12/31/9999','mm/dd/yyyy')
              - to_date('01/01/1753','mm/dd/yyyy')
             )
             / 7) diff
FROM DUAL;
 

Remove Duplicates in List

List list = new List(new string[] { "cat", "Dog", "parrot", "dog", "parrot", "goat", "parrot", "horse", "goat" });
Dictionary wordCount = new Dictionary();

//count them all:
list.ForEach(word =>
{
string key = word.ToLower();
if (!wordCount.ContainsKey(key))
wordCount.Add(key, 0);
wordCount[key]++;
});

//remove words appearing only once:
wordCount.Keys.ToList().FindAll(word => wordCount[word] == 1).ForEach(key => wordCount.Remove(key));

Console.WriteLine(string.Format("Found {0} duplicates in the list:", wordCount.Count));
wordCount.Keys.ToList().ForEach(key => Console.WriteLine(string.Format("{0} appears {1} times", key, wordCount[key])));

Automatic Timeout in Session

To Implement auto redirection after session expires....
do the following:

Write this code in to the masterpage's cs file

protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
this.HeadContent.Controls.Add(new LiteralControl(
String.Format("",
SessionTimeOutWithin * 60, PageToSentAfterSessionTimeOut)));
}


Now also add below methods in masterpage...

public string PageToSentAfterSessionTimeOut
{
get { return "CheckSessionTimeOut.aspx"; }
}

public int SessionTimeOutWithin
{
get { return Session.Timeout; }
}

Now in WebConfig set the timeout.
Here I have set timeout to 1 minute for checking purpose....
please change it as per your requirement.

sessionState mode="InProc" cookieless="true" timeout="1">