Posts

Showing posts from 2011

Session Timeout in IIS 7 - Worker Process of ApplicationPool

Image
Problem Recently while testing my application, I was facing problem of Session time out. By Default Session time is 20 mins and I wanted to extend it Attempts if we want to extend it we can set in web.config within System.web tag <sessionState mode="InProc" timeout="30"></sessionState> that I already have done. I set it as 30 mins. but still my session was getting timed out after 20 min. So I doubt that it doesn’t apply to my Code so I set It by code also like System.Web.HttpContext.Current.Session.Timeout = 30; still no progress Resolutions after a long invastigation I came to know Its because Of Default Settings of ApplicationPool for the application in IIS. There is a setting for Worker process of IIS which will set memory and resource to allot to application application wide. in my case I was testing my application alone. So application was being idle for more than 20 min to check weather session is alive or not.. To open the set...

Steps to Remove Menu options in Export for Report Page in SSRS

Hi, In SSRS(Sql Server Reporting Service), I wanted to remove extra options to export my report. Here are the steps to remove option to export like (word, Excel, PDF, MHTML etc...) in SSRS (Sql Server Reporting Service) Installation folder may be different from MSSQL.1, can be MSSQL.x (search for rsreportserver.config under Program Files\Microsoft SQL Server if not found) Here are the steps for Disabling Excel Export Option in Reporting Services - Go to Database server where reporting services is installed, open the rsreportserver.config file located at <Drive Letter>:\ Program Files\Microsoft SQL Server\MSSQL.3\Reporting Services\ReportServer   Go to section.   Change this entry to i.e. add Visible="false" for Excel rendering extension   Same for PDF.   Happy Reporting

Create Excel File From DataTable

Hello Friends, Many times we need to create Excel files in our application using existing Data. I have figured out a class which will help to create excel file by just passing DataTable and preferred location to generate on server. please download the cs file from here .. and use it :) here is full code using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; using System.Xml; public class ExcelHelper { private static readonly ExcelHelper _instance = new ExcelHelper(); public static ExcelHelper Instance { get { return _instance; } } /// <summary> /// Create one Excel-XML-Document with SpreadsheetML from a DataTable /// </summary> /// <param name="dataSource">Datasource which would be exported in Excel</param> /// <param name="fileName">Name of exported file</param> public ...

Scroll to particular record in GridView

Hello Friends, here is a tip to scroll the gridview to particular record. the basic concept is html scrolling. to scroll at particular position create an anchor tag with name as address (eg. #ScrollPoint '# is must') now redirect the page to the location using javascript call window.location.href = "#ScrollPoint";   same thing can be achieved by anchorlink href here is sample code HTML Page <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="return MoveTo();" /> <div style="height: 100px; overflow: auto;"> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"> <Columns> <asp:TemplateField HeaderText="ID" SortExpression="ID"> <EditItemTemplate...

Power of common table expression (CTE)

Image
Hello friends, Recently I came across a case where I was supposed to generate report for Customer based on services availed to him and for that I used A common table expression (CTE) and it really impressed. initially I referred this great document of MSDN http://msdn.microsoft.com/en-us/library/ms190766.aspx here is my Table of data.(Actual Tables are not like this, I have managed a simplified Table for the Demo.) Here is query to generate Table declare @t table (id int identity,CustID int, AgreementName varchar(100), ServDate Datetime,Price float) insert @t select 70 ,'First Agreement',CONVERT(datetime,'2011-01-05'),10 insert @t select 70 ,'Second Agreement',CONVERT(datetime,'2011-01-06'),10 insert @t select 75 ,'First Agreement',CONVERT(datetime,'2011-03-14'),10 insert @t select 70 ,'Second Agreement',CONVERT(datetime,'2011-01-05'),30 insert @t select 75 ,'Third Agreement',CO...

Access UserControl from Page

Image
Hi.. To perform some reparative operation in application, its preferred to use UserControls. Not necessary to have same display and bindings at everyplace. In that case we need to set values or call methods or pass values accordingly. Here I have tried to figure out three cases, Hope it is helpful. Pass Table to Usercontrol and Set dynamically value to Controls Set Properties of control Call Usercontrol's Methods

Set Default Value as Function to column of a Table

Image
Hello, Generally we need to set default value to particular column in Database Table like isActive is true, IsDeleted is false. same way many times we set CreatedOn Date as CurrentDate and that is by query of insert GetDate(). Static Values : Its very easy to set some static value as Default value for column and that is as follow : Functions : Set Default Date for Createdon Field as Follow : User Defined Functions : Set User Defined function as Default Value as follow: In my case I am supposed to get Random Hexa Code for Color. so I Have created an User Defined function for that CREATE FUNCTION [dbo].[GetRandomColorCode] ( ) RETURNS varchar(6) AS BEGIN Declare @Color varchar(6) RETURN (SELECT MyNewID FROM dbo.MyNewID) END Now set the function in columns as follow : If this do not allow us to set Default value try following query to set ALTER TABLE dbo.Table_1 ADD CONSTRAINT DF_Table_1_ColorCode DEFAULT ([dbo].[GetRandomColorCode]()) FOR ColorCode GO Al...

Track Error in Javascript Page

Hi Many times we have faced problems to find what is javascript errors and exactly where?? To track javascript error, It is a good practice to write code in Try..Catch but sometimes some small syntax error are not allowing to execute the whole js file. so to track such error during development, we can track by this sample code <script type="text/javascript"> onerror = CallOnError; function CallOnError(msg, url, line) { var strErrMessage = ""; strErrMessage += "Message: " + msg + "\n"; strErrMessage += "Page: " + url + "\n"; strErrMessage += "Line Number: " + line + "\n\n"; alert(strErrMessage); return true; } </script> Here is a sample error try to put on your page <script type="text/javascript"> alert('This is First Test Page); </script...

Second Highest Salary- Sql Query

Image
Create Table #Emp(id int identity primary key, Emp varchar(100), Salary int) insert into #Emp select 'XXXX',17000 union all select 'DDDD',21000 union all select 'WWWW',30000 union All Select 'HHHH',21000 union All select 'CCCC',30000 union All Select 'TTTT',21000 union All SElect 'PPPP',21000 select * from #Emp select #Emp.* from (select ROW_NUMBER() over (order by salary desc) as RowNumber, Salary from #Emp group by Salary) as tempEmp inner join #Emp on tempEmp.Salary = #Emp.Salary where tempEmp.RowNumber=2 Drop Table #Emp Data Will Look like this Output will be like this

Protect image from being copied

Image
Hello Friends, Many times I am asked to protect some copyrighted images over web, so finally I have found a better way to protect from being copied. There are some cases by which we can copy the image Here I have taken care of following cases Right click on image and Save the Image Save the Entire page and all images displayed on page will be downloaded to its Data Folder in mozila Firefox, We can save the media files by following steps Right click on Page, select “View Page Info” It will open a window, Select “Media” tab, here a list of all files will be available select particular file and click on “Save As” button to save the media Now Let’s Start our main topic,that is protect image from being copied There is a concept called Data URI scheme . Generally to display any image on page, we use Relative_URL and if we display image using this, the images can be easily copied. Here we will save image in database and retrieve the same To Create table CR...

Fetch Data from Control Without Loop- Best Use of LINQ

Hi friends…. Many times I need to generate collection type Data from GridView or Repeater or any other control.. and in that case I used to loop through each rowitem of particular control.. here each row of repeater is listitem of LINQ query. same way you can perform for all DataBound Controls like GridView, Repeater, DataList, DropDownlist, CheckboxList, Radiobuttonlist etc… but after using LINQ , I am able to do that very easily here is sample of Repeater control to Get List of data List ctrls = (from item in rptctrlList.Items.Cast () where ((CheckBox)item.FindControl("chkctrl")).Checked select new ctrlInfo() { ctrlId = Convert.ToInt32(((HiddenField)item.FindControl("hdnctrlId")).Value), UserctrlId = Convert.ToInt64(((HiddenField)item.FindControl("hdnUserctrlId")).Valu...

Apply Frame to Image with CSS

Image
Hello Many times we need to display image like profile image or advertisements and at that time we need to decorate it within frame…   Here we have a simplest way to apply frame which will help to set frame to any size image and unique for all.. here I have a sample code for it <html> <head> <style> img { background: url("shadow.gif") no-repeat scroll right bottom transparent; border-color: #EEEEEE -moz-use-text-color -moz-use-text-color #EEEEEE; border-right: medium none; border-style: solid none none solid; border-width: 1px medium medium 1px; padding: 4px 10px 10px 4px;} </style> </head> <body> <img src='https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxKSyD46sNlLs8yYLBFMz_YGOiYANzbKSUPo5YT5f2K34QvZgGOWTWF_s_aWPoe4zuVafRytM6346dkW7bkjptRImMMCLWyaCxtGgAjPD97wa7HWZ_l94H2uWxlU8V2UKIJPgvyj7sTO5x/s220/Sandeep.JPG'> </body> </html> and the you can have any kind of frame imag...

Publish webservice locally without separate hosting

Image
Hi.. here is a way to deploy web service withing project... Here are the steps for it in your Project... right click on Project in Solution Explorer. Click on Add new Item and Select "Web Service" Name it as per required... and Click on "Add" Button... now you have your web service ready in local environment... put you code in Web Service .Cs file Build the Source and make sure its error free... now Deployment Part Right click on "References" in Solution Exporer, You will find.. three Options like     Add Reference     Add Web Reference     Add Service Reference Select "Add Web Reference", you will get a Pop up, in Below there are three links Browse to:     * Web services in this solution     * Web services on the local machine     * Browse UDDI Servers on the local network select "Web services on the local machine " You will get a list ...