what I learn is what u c

Planning to Host WordPress Blog

leave a comment »

Written by gchandra

December 5, 2008 at 12:04 am

Posted in Web Coding

Tagged with ,

Handling multiple configuration settings (Development, Staging, Production) gracefully.

leave a comment »

In 2.0 multiple connectionStrings & appSettings can be handled very easily using the attribute “configSource”

create a new xml file devAppSettings.config under a new folder myConfigsettings

(continue reading…)

Written by gchandra

May 1, 2008 at 8:52 pm

Posted in Asp.Net, Web Coding

Tagged with

How to Preserve Fileupload value in ?

leave a comment »

If you form has Fileupload control along with other controls like dropdownlist, calendar.. you will be facing standard problem of Fileupload control losing value when other controls are selected.

Click here to read the article in full…


Written by gchandra

May 1, 2008 at 7:35 pm

Moved to own domain

leave a comment »

I have moved my blog here..

See you there

Written by gchandra

March 1, 2008 at 1:32 am

Posted in Web Coding

Disable .xml file generation when building Asp.Net application

leave a comment »

Visual Studio 2005 – Compile Options

.XML files are used to create Documentation.

If you need to disable them, then

Project Properties > Compile and Uncheck Generate XML Documentation file option.

Compile Options

Written by gchandra

February 22, 2008 at 9:19 pm

Posted in Web Coding

Tagged with , , , ,

Disable .pdb file generation in Release Mode

with 3 comments

Visual Studio 2005 – Compile Options

In Visual Studio 2005, .pdb file gets generated in Debug mode and Release mode.

In debug mode it loads the entire symbol table, in Release mode it loads the key symbols.

In Release mode, the generated .pdb can be deleted very well deleted. (Because framework does not uses it)

To disable .pdb generation in Release mode, goto

Project Properties > Compile Tab > Advanced Compile Options

Compile Options

Goto Generate Debug Info (dropdown list) and select None.


Written by gchandra

February 22, 2008 at 9:15 pm

SQL Server 2005 : Access Tables / Entities across Servers.

leave a comment »

Accessing objects (tables..) across servers (SQL Server) is very simple.

Step 1: Create a link between two servers

Goto Query Window

EXEC sp_addlinkedserver
   N'SQL Server'

‘PRODSVR’  is the name of the Server.Execute it.

Step 2: Setup Permission between Servers.In Management StudioGotoServer Object >> Linked Servers >>

PRODSVR (See Image)

Linked Servers List

Right Click on PRODSVR goto Properties and make changes as given below.




Step 3: To access the tables in other server

Use the following  hirearchy


To access Person.Address table from AdventureWorks database

Select * From PRODSVR.AdventureWorks.Person.Address

Advantages :

1. Update Production server with data from development server. (SSIS is alternate way)

2. Allow users to access production database without multiple logins. (windows authentication or SQL authentication) 

kick it on

Written by gchandra

February 18, 2008 at 3:31 pm

SQL Server, Clean your Database Records and reset Identity Columns, The Shortest Path

with 4 comments

(Copied from Moses’s Blog for my reference)

Well, I had a small issue regarding writing a script to clean a database we have and reset its identity columns in all tables. Although the database wasn’t huge one (less than 100 tables) I had to trace relations to be able to delete child table’s records before parent’s ones because of the foreign key constraints. The solution is disable the foreign keys and delete records with no fear of any errors then enables the constraints again.
Well, I found a solution to disable all constraints without the need to go on each table and disable it manually. and I was happy to know that I can use this solution in deleting all records from all tables. Not only this I was able to use the same solution to reset identity columns in all tables.

The solution was to use this built in stored procedure sp_MSforeachtable. For help about this proc search for it in Books online or use this sp_helptext sp_MSForeachtable.

Now back to my 6 lines, bellow is how I re-zeroed my Database:

1: /*Disable Constraints & Triggers*/
2: exec sp_MSforeachtable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'
3: exec sp_MSforeachtable 'ALTER TABLE ? DISABLE TRIGGER ALL'
5: /*Perform delete operation on all table for cleanup*/
6: exec sp_MSforeachtable 'DELETE ?'
8: /*Enable Constraints & Triggers again*/
9: exec sp_MSforeachtable 'ALTER TABLE ? CHECK CONSTRAINT ALL'
10: exec sp_MSforeachtable 'ALTER TABLE ? ENABLE TRIGGER ALL'
12: /*Reset Identity on tables with identity column*/
13: exec sp_MSforeachtable 'IF OBJECTPROPERTY(OBJECT_ID(''?''), ''TableHasIdentity'') = 1 BEGIN DBCC CHECKIDENT (''?'',RESEED,0) END'

Written by gchandra

February 18, 2008 at 10:23 am

Organize your SQL Server 2005 tables in a better way !!

leave a comment »

When you create tables in SQLServer (2005) by default its all get created under default schema. (dbo.)

If you have too many tables then the table list could be confusing / clumsy.

Here enters Schema

(see image)

Schema Example

To organize your tables into meaningful groups (or namespaces)

First create a schema


Then Alter your existing table

TRANSFER dbo.Contact

So now that you have grouped your tables into different schemas.

How to use them ? The usual way but with schema name added to it.

SELECT * FROM Person.Contact

What is Schema ? (from MSDN)Beginning in SQL Server 2005, each object belongs to a database schema. A database schema is a distinct namespace that is separate from a

database user.  Schemas can be created and altered in a database, and users can be granted access to a schema. A schema can be owned by any

user, and schema ownership is transferable.

In previous versions of SQL Server, database users and schemas were conceptually the same object. Beginning in SQL Server 2005, users and schemas

are separate, and schemas serve as containers of objects.

Written by gchandra

February 6, 2008 at 9:07 am

AJAX – Export to Excel / Word

with 17 comments

If you are using Update Panel and try to Export gridview contents to EXCEL or Word, your page will throw nasty error. “Sys.WebForms.PageRequestManagerParserErrorException”

Its because AJAX & Response.write don’t go together.  By calling Response.Write() directly you are bypassing the normal rendering mechanism of ASP.NET controls. The bits you write are going straight out to the client without further processing (well, mostly…). This means that UpdatePanel can’t encode the data in its special format.

There are couple of ways to solve this problem.

1. Place the Export Button outside of Update Panel.

2. By Pass the Export Button using <Triggers>

            <asp:PostBackTrigger ControlID=”cmdExport” />

if your Export button is part of UserControl then specify usercontrolid:buttonid

            <asp:PostBackTrigger ControlID=”uscSelCtl:cmdExport” />

More Reading…

Written by gchandra

January 8, 2008 at 10:12 am Web Service Timing Out (0x80004005)

leave a comment »

Recently if your webservices started failing / timing out it its worth your time to take a look at this support article.

“HttpException (0x80004005): Request timed out.”

“System.InvalidOperationException: There were not enough free threads in the ThreadPool object to complete the operation”

 Contention, poor performance, and deadlocks when you make Web service requests from ASP.NET applications

Related Reading :

Item 5 talks about Asp.Net WS

Written by gchandra

January 8, 2008 at 9:47 am

Asp.Net Filter Datatable by Column

with 6 comments

Filter Datatable by Rows

If you need to get subset of a big dataset into datatable Rowwise …

Dim dtEmp as DataTable
Dim dsEmployee as New DataSet

dsEmployee = someobject.getdata()  'dataset can be populated in many ways which is not explained here.

Dim sExpr as String
Dim drRows() as DataRow, drSingleRow as DataRow

sExpr = "EmpID > 100"  'Condition

drRows = dsEmployee.Tables(0).Select(sExpr)

'If you need to add Sort Order it can be added to sExpr

Dim sSortOrder as String
sSortOrder = "EmpName DESC"
drRows = dsEmployee.Tables(0).Select(sExpr,sSortOrder)

For Each drSingleRow in drRows

' Datatable dtEmp has filtered records

Filter Datatable by Column

If you need to get subset of big dataset into datatable columnwise…

Dim dtEmp as DataTable
Dim dsEmployee as New DataSet

dsEmployoee = someobject.getdata()  'dataset can be populated in many ways which is not explained here.

'This copies the structure and data

dtEmp = dsEmployee.Tables(0).Copy

dtEmp.Columns.Remove("Unwanted Column 1")
dtEmp.Columns.Remove("Unwanted Column 2")
dtEmp.Columns.Remove("Unwanted Column 3")

Written by gchandra

January 7, 2008 at 4:13 pm

SQL Server 2005 : Verify table already exists

with 2 comments

Verifying that an object exists

If the table exists, it is deleted. If the table does not exist, the DROP TABLE statement is not executed.

IF OBJECT_ID (N’dbo.AWBuildVersion’, N’U’) IS NOT NULL
 DROP TABLE dbo.AWBuildVersion;

Syntax :

OBJECT_ID (‘object_name’, [‘object_type’])

Object Type is optional, and possible values it can hold are.. (Items in bold are frequently used)

Object type:

AF = Aggregate function (CLR)

C = CHECK constraint

D = DEFAULT (constraint or stand-alone)

F = FOREIGN KEY constraint

PK = PRIMARY KEY constraint

P = SQL stored procedure

PC = Assembly (CLR) stored procedure

FN = SQL scalar function

FS = Assembly (CLR) scalar function

FT = Assembly (CLR) table-valued function

R = Rule (old-style, stand-alone)

RF = Replication-filter-procedure

SN = Synonym

SQ = Service queue

TA = Assembly (CLR) DML trigger

TR = SQL DML trigger

IF = SQL inlined table-valued function

TF = SQL table-valued-function

U = Table (user-defined)

UQ = UNIQUE constraint

V = View

X = Extended stored procedure

IT = Internal table

Written by gchandra

December 4, 2007 at 12:01 pm

Posted in Database

Tagged with , , ,

Prevent Session Timeout in

with 17 comments

Prevent Session Timeout in [VB]

ASP.Net 2.0 [VB]

Inspired by this article from Code Project. [Thanks Ach1lles ]

I slightly modified few things to work for VB and VS2005 environment. The code works perfect and I’m very happy with it.First I created a Module file and created this function.

Public Function KeepAlive() As String

        Dim int_MilliSecondsTimeOut As Integer = (HttpContext.Current.Session.Timeout * 60000) - 30000
        Dim sScript As New StringBuilder
        sScript.Append("<script type='text/javascript'>" & vbNewLine)
        'Number Of Reconnects
        sScript.Append("var count=0;" & vbNewLine)
        'Maximum reconnects Setting
        sScript.Append("var max = 6;" & vbNewLine)
        sScript.Append("function Reconnect(){" & vbNewLine)
        sScript.Append("count++;" & vbNewLine)
        sScript.Append("var d = new Date();" & vbNewLine)
        sScript.Append("var curr_hour = d.getHours();" & vbNewLine)
        sScript.Append("var curr_min = d.getMinutes();" & vbNewLine)
        sScript.Append("if (count < max){" & vbNewLine)
        sScript.Append("window.status = 'Refreshed ' + count.toString() + ' time(s) &#91;' + curr_hour + ':' + curr_min + '&#93;';" & vbNewLine)
        sScript.Append("var img = new Image(1,1);" & vbNewLine)
        sScript.Append("img.src = 'http://localhost/myapp/reconnect.aspx';" & vbNewLine)

        sScript.Append("}" & vbNewLine)
        sScript.Append("}" & vbNewLine)
        sScript.Append(int_MilliSecondsTimeOut.ToString() & "); //Set to length required" & vbNewLine)

        KeepAlive = sScript.ToString
End Function

All this code does is, build a simple javascript function and its called from server side.The works like this,- Gets the current session timeout duration.
– Subtract 30 seconds from it and assign it to MilliSecondsTimeOut variable
– Create a Reconnect() javascript function
– Create a global variable with max value 6
– Get current hour and Min [just for displaying the last refresh time]
– Verify whether count is less than max value (ie 6)
– If so, change the window status with Text
– Create a dummy image and set reconnect.aspx url as its source [this way a call is made to server and it wont session timeout]Create a timer using window.setInterval and assign the MilliSecondsTimeOut value.
[this way this function is called 30 seconds before session timeout]Tha max value (6) can be set to any number. If its 6 then this session timeout is avoided 5 times.

Default session timeout is 20min. 20 * 5 = 100 mins. Which is good for non-secure page.


On the pages where I want to prevent Session Timeout I entered this line.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  'dont forget to add this line 
  Page.ClientScript.RegisterClientScriptBlock(Me.GetType, "reconn key", KeepAlive())
 If Not Page.IsPostBack Then
 End If

Catch eX as Exception
End Try
End Sub

Created reconnect.aspx in Visual Studio and deleted the .vb and .designer.vb files.This is the final version of reconnect.aspx

<%@ Page Language="vb" AutoEventWireup="false"%>
<%@ OutputCache Location="None" VaryByParam="None" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<a href="" mce_href=""></a>">
<html xmlns="<a href="" mce_href=""></a>" >

Note : When you compile the project sometimes, VS2005 complains reconnect.aspx is not in right format.
So I EXCLUDED this file from my project. Now VS 2005 will compile without complaining and the logic will also work.- Happy Programming

Written by gchandra

November 26, 2007 at 3:42 pm

Copy Datatable from one Dataset to another Dataset

with 10 comments

 Copying a datatable from one dataset  to another was not that straightforward as I thought.

Dim dsSource As New DataSet
Dim dsDestination As New DataSet

'Your way to get data from XML or DB.
dsSource = object.getdata()

dsDestination = object.getmoredata()

'This is important, without this it will result in error
'when you try to copy the datatable from one dataset to another

dsSource.Tables(0).TableName = "NewTableName"


dsDestination.Tables(0).Tablename = "SomeTable"
dsDestination.Tables(1).Tablename = "NewTableName"   'The one we copied from other Dataset

Note 1 : When you are using more than one datatable in a dataset it is advisable you name the datatables.

Note 2 : These kinds of scenarios arise, when you are trying to establish Relation between datatables in a dataset.

(Cascading master – detail relation)

Written by gchandra

November 15, 2007 at 2:12 pm

Posted in Asp.Net, Web Coding

Tagged with , , ,

Creating dynamic, fancy EmptyDataText for GridView

with 2 comments

Gridview has capability to display “default” messages when “No data” exists during binding.

Standard Way in .aspx

<asp:GridView ID=”gvControl” runat=”server” AutoGenerateColumns=”False” GridLines=”None” CellPadding=”0″ CellSpacing=”0″ OnRowDataBound=”gvCategories_RowDataBound” BackColor=”#dddddd” ShowHeader=”false” EmptyDataText=”<BR> No data exists <BR><BR>“>

Fancy Way (.vb or .cs)

You can make it fancy & dynamic by doing it in code behind.


Create fancy texts using WordArt (MS Word) and copy it to Image Editor (, gimp, Paint) and save it as JPG.

gvControl.EmptyDataText = "<img src='~/images/NoData.jpg' border='0'>"
gvControl.EmptyDataRowStyle.HorizontalAlign = HorizontalAlign.Center

Note: When you use emptydatatext in codebehind donot forget to use databind.

Written by gchandra

October 24, 2007 at 2:17 pm

Posted in Asp.Net, Web Coding

Tagged with , ,

‘The invoked member is not supported in a dynamic module.’

with one comment

Error ‘The invoked member is not supported in a dynamic module.’ while generating exception string

While Using ASPUnhandledException.dll for exception handling, I received this error via email.

This error message was not at all helpful in production environment. 

On careful debugging I found out that my Stored Proc failed.

Instead of giving the reason for Stored Proc failure it gave this obscure message. If  someone knows why it gives this message it will be helpful.

(reason my sp failed was because I was calling a non-existing user defined function)

Written by gchandra

October 22, 2007 at 2:47 pm

How to add Company & Version details to your Assembly file or .dll ?

with one comment

If you want to add details like (Your [company] name, Product name, Copyright info, Version Number) to your custom library ?

ex :

Assembly File Properties

Its very simple.

Open Assembly.vb  or Assembly.cs and modify the following items.

You can add more attributes that are not given here. Use Visual Studio intelli-sense to find more attributes.


<Assembly: AssemblyTitle(“Your Library Name”)>
<Assembly: AssemblyDescription(“Description about the library”)>
<Assembly: AssemblyCompany(“Your Company name”)>
<Assembly: AssemblyProduct(“Product Name”)>
<Assembly: AssemblyCopyright(“Copyright ©  2007”)>
<Assembly: AssemblyTrademark(“Product Trademark”)>
<Assembly: ComVisible(False)>

<Assembly: AssemblyVersion(“”)>
<Assembly: AssemblyFileVersion(“”)>

Written by gchandra

October 16, 2007 at 2:56 pm

Posted in Asp.Net

Validation (XHTML 1.0 Transitional): A newer construct is recommended.

with one comment

Validation (XHTML 1.0 Transitional): Attribute ‘name’ is considered outdated. A newer construct is recommended.  

Deprecated Elements & Attributes and Newer Constructs

XHTML 1.0 Transitional


Newer Constructs

<menu /> Use another list type.
<u /> Use CSS property “text-decoration” and set its value to “underline”.
<s /> Use CSS property “text-decoration” and set its value to “line-through”.
<strike /> Use CSS property “text-decoration” and set its value to “line-through”.
<basefont /> Use CSS styling and set the “font-family” property to desired font.
<font /> Use CSS styling to set the property of the element, such as a DIV or SPAN.The CSS properties include:

  • color
  • font-family
  • font-size
  • text-decoration
  • text-align
  • text-indent
  • text-transform
  • font-weight
<applet /> Use the <object /> tag
<isindex />  Use the <input /> tag
<i /> Use the <em /> tag
<b /> Use the <strong /> tag

Elements / Attributes

Newer Constructs

name Use the ID attribute
align Use the CSS property “text-align”
background Use the CSS property “background-image” or “background”.
bgcolor Use the CSS property “background-color” or “background”.
text Use the CSS property “color” for the “body” style
link Use the CSS section “a:link” and set the property “color”.
vlink Use the CSS section “a:visited” and set the property “color”.
alink “a:hover” and set the property “color”.
div / p / h1…h6
align Use the CSS property “text-align”.
ul / ol / li
type   Use the CSS property “list-style-type” or “list-style”.
compact       This attribute has been removed from the HTML DOM 1.0
align   Use the CSS property “text-align”.
noshade       Use the CSS property “color”.
size    Use the CSS property “height”.
width  Use the CSS property “width”.
width  Use the CSS property “width”.
name Use the attribute “id”.
clear  Use the CSS property “clear”.
align Use the CSS property “vertical-align” and “text-align” in the parent tag
border Use the CSS property “border”.
hspace Use the CSS property “padding”.
vspace Use the CSS property “padding”.
name Use the attribute “id”.
align Use the CSS property “vertical-align” and “text-align” in the parent tag
border Use the CSS property “border”.
hspace Use the CSS property “padding”.
vspace Use the CSS property “padding”.
name Use the attribute “id”.
align Use the CSS property “vertical-align” and “text-align”
name Use the attribute “id”.
align Set table’s CSS properties left-margin and right-margin at “auto” for centering, or right-margin to 0 for right alignment, or the left-margin to 0 for left alignment.
bgcolor Use the CSS property “background-color”.
bgcolor        Use the CSS property “background-color”.
td, th
nowrap Use the CSS property “word-wrap”.
bgcolor Use the CSS property “background-color”.
width  Use the CSS property “width”.
height Use the CSS property “height”.

PDF copy of the same is attached for download.

Written by gchandra

October 15, 2007 at 12:56 pm

Posted in Visual Studio

How strong User ID and Password should be ?

with 3 comments

Few thoughts on how to  enforce strong userids and passwords.

UserIDs can be email address. (An email can be sent to the ID with a link to make sure email id is valid)

– Password must be between 8 and 14 characters.
– Password must contain at least one number, at least one English uppercase character, and at least one English lowercase character.
– Password must contain one special character like #,*,&
– Password may not have more than two consecutive identical characters.

Ex : This is valid :  grEen12#   but  grEEEn12# is not valid

– Password cannot be the same as your previous three passwords.

– Password cannot be similar as your previous three passwords.

Ex : If this is your old password grEen12#, new Password cannot be grEen13#

– Password cannot be the same as or contain your User ID or contain the word “password” or contain your site / company name.

Ex : If your site is abcjewellers then password cannot be   aBcJewellers#1 or paSSword$1

– Password should expire every 60 days.

Written by gchandra

October 15, 2007 at 11:07 am

Posted in Tips and Tricks

Tagged with , ,