I have come across this error multiple times at work. This problem occurs because the default value for the maxRequestLength parameter in the section of the Machine.config or Web.Config file is 4096 (4 megabytes). As a result, files that are larger than this value are not uploaded by default.
To resolve this problem, use one of the following methods:
- In the Machine.config file, change the maxRequestLength attribute of the <httpRuntime> configuration section to a larger value. This change affects the whole computer.
- In the Web.config file, override the value of maxRequestLength for the application. For example, the following entry in Web.config allows files that are less than or equal to 1 GB to be uploaded:
<httpRuntime maxRequestLength="1048576" />Max value for maxRequestLength attribute is "1048576" (1 GB) for .NET Framework 1.0 or 1.1 and "2097151" (2 GB) for .NET Framework 2.0.
Note: During the upload process of large files, built-in ASP.NET loads the whole file in memory before the user can save the file to the disk. Therefore, the process may recycle because of the memoryLimit attribute of the processModel tag in the Machine.config file. More info you can find in Microsoft KB article: http://support.microsoft.com/default.aspx?scid=kb;EN-US;295626
Sunday, December 31, 2006
Error "System.Web.HttpException: Maximum request length exceeded"
Sunday, December 17, 2006
Export GridView Data in MS-Excel
In the following example, I will demonstrate how to export GridView Data into MS-Excel using VB.NET. It uses the same business object to select data from database. I have simply formatted the GridView control from previous example.
Page Name: ExportGridViewToExcel.Aspx
------------------------------------
Note: You will be required to add - EnableEventValidation = "False" at Page Directive in order to Export to work.
-------------------------------------
Code Snippet
- <%@ Page Language="VB" AutoEventWireup="false" EnableEventValidation = "False" CodeFile="ExportGridViewToExcel.aspx.vb"
- Inherits="ExportGridViewToExcel" %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" >
- <head runat="server">
- <title>Export Customers Data</title>
- </head>
- <body>
- <form id="frmCustomer" runat="server">
- <div style="text-align:center">
- <asp:Button ID="btnExportToExcel" runat="server" Text="Export to Excel" /><br />
- <asp:Label ID="lblMessage" runat="server" Text=""></asp:Label> <br />
- <asp:GridView ID="gdvCustomer" DataKeyNames="CustID" runat="server" AllowPaging="True" DataSourceID="odsCustomer"
- AutoGenerateColumns="False" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None"
- BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Vertical"
- RowStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left">
- <Columns>
- <asp:BoundField DataField="CustID" HeaderText="Cust ID" />
- <asp:BoundField DataField="CustName" HeaderText="Name" SortExpression="CustName" />
- <asp:BoundField DataField="CustAddress" HeaderText="Address" SortExpression="CustAddress"/>
- </Columns>
- <EmptyDataTemplate>
- No Customer Record Found.
- </EmptyDataTemplate>
- <FooterStyle BackColor="#CCCC99" />
- <RowStyle BackColor="#F7F7DE" />
- <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
- <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
- <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
- <AlternatingRowStyle BackColor="White" />
- </asp:GridView>
- <asp:ObjectDataSource ID="odsCustomer" runat="server"
- SelectMethod="GetCustomers"
- TypeName="Vishwa.Example.Business.CustomerFac" >
- </asp:ObjectDataSource>
- </div>
- </form>
- </body>
- </html>
Code Behind : ExportGridViewToExcel.Aspx.vb
Code Snippet
- Option Explicit On
- Option Strict On
- Imports System.IO
- ' Author : Vishwa Mohan
- ' Date : 12/15/2006
- ' Class : ExportCustomer
- ' Purpose: To Export Customers Record into Excel
- Partial Class ExportGridViewToExcel
- Inherits System.Web.UI.Page
- Protected Sub btnExportToExcel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExportToExcel.Click
- If gdvCustomer.Rows.Count + 1 < 65536 Then
- Me.lblMessage.Text = ""
- Me.gdvCustomer.AllowPaging = False
- 'If you are binding GridView under Code Behind
- 'Me.gdvCustomer.DataSource = GetCustomer
- Me.gdvCustomer.DataBind()
- Dim tw As New StringWriter()
- Dim hw As New System.Web.UI.HtmlTextWriter(tw)
- Dim frm As HtmlForm = New HtmlForm()
- Page.Response.ContentType = "application/vnd.ms-excel"
- Page.Response.AddHeader("content-disposition", "attachment;Customer.xls")
- Page.Response.Charset = ""
- Page.EnableViewState = False
- frm.Attributes("runat") = "server"
- Controls.Add(frm)
- frm.Controls.Add(gdvCustomer)
- frm.RenderControl(hw)
- Response.Write(tw.ToString())
- Response.End()
- Me.gdvCustomer.AllowPaging = True
- 'If you are binding GridView under Code Behind
- 'Me.gdvCustomer.DataBind()
- Else
- Me.lblMessage.Text = "Too many rows - Export to Excel not possible"
- End If
- End Sub
- End Class
Page at the run Time
Saturday, December 02, 2006
The Four Wives
He also loved his third wife a lot - he guarded her richness and grandeur against the evil eyes of then neighboring kings and others.
He loved his second wife so much that he shared all his thoughts especially with her. But unfortunately he never loved his first queen - he ignored her very presence and enjoyed with the other queens.
Days passed by and one day it so happened that the king fell terribly sick and the best of the physicians in the kingdom and the world could find a cure. It was certain that he was staring at his end and he was on his final days.
He calls his fourth queen over and sadly says "Look, I am on my deathbed and will leave this world anytime now. When I was hale and hearty, I used to take you everywhere that I went. Will you accompany me when I leave to the other world?" To his utter shock, the Queen refused to do so and made it abundantly clear that it was unreasonable for the king to expect this and she would not like to give up her life for him. Though shocked, he did not lose hope; he calls his third queen and poses the same question to her. The shock was greater, she refuses to accompany him and moreover she replied that she would remarry after his death and continue to lead a happy life. The king was crestfallen at this outrageous reply from his dearest queens but again rests his hopes on the second queen. He looks at her and she pretends to be sympathetic to him and replies, "O dear, when you die, I cannot accompany you" and justifies this decision saying, "Your last rites will be performed as per the scriptures and I will take the responsibility to ensure this"
The king realized the reality at this fag end of his life. He realized the bitter truth that no one would accompany him nor would be available during his final days. While he was brooding over this fact, his first wife says, "O sweetheart, I am with you wherever you go. Don't you worry that you will have to make this last journey alone" The king was surprised and then realized that she was the true wife who loved him for what he was - not his riches not even his health. But his regret was that it was too late to make amends and shower her with his love.
Yes...like this king, we all have four wives.
The fourth wife is our body - a physical commodity that burns into ashes or disintegrates back to the earth at the end. The third wife is the wealth that we earn which would be shared and become property of others after our death. The Second wife is the relatives and friends who can only remain with us till the cemetery or crematorium. The First wife is the one which remains in our heart, the Divine or God, which remains with us in all our births and rebirths. It saves us from grief at the later stages if we adopt our spiritual practices and be devoted to the divine during our younger years.
Saturday, November 11, 2006
Surya Namaskara - Sun Salutation
Tuesday, October 31, 2006
We're All Cracked Pots
At the end of the long walk from the stream to the house, the cracked pot arrived only half full.
For a full two years this went on daily, with the bearer delivering only one and a half pots full of water to his house. Of course, the perfect pot was proud of its accomplishments, perfect for which it was made. But the poor cracked pot was ashamed of its own imperfection, and miserable that it was able to accomplish only half of what it had been made to do.
After 2 years of what it perceived to be a bitter failure, it spoke to the water bearer one day by the stream. I am ashamed of myself, and because this crack in my side causes water to leak out all the way back to your house.
The bearer said to the pot, Did you notice that there were flowers only on your side of the path, but not on the other pot's side that's because I have always known about your flaw, and I planted flower seeds on your side of the path, and every day while we walk back, you've watered them.
For two years I have been able to pick these beautiful flowers to decorate the table. Without you being just the way you are, there would not be this beauty to grace the house.
Each of us has our own unique flaws. We're all cracked pots. But it's the cracks and flaws we each have that make our lives together so very interesting and rewarding. Don't be afraid of your flaws. Acknowledge them, and you too can be the cause of beauty. Know that in our weakness we find our strength.
Source : Sent by a friend
Saturday, October 28, 2006
The Word Hindu and India
The word 'Hindu' is NOT a Sanskrit word. Numerous scholars say it is not found in any of the Vedic literature. So it is important to know how such a name can truly represent the Vedic culture. And without the Vedic literature, there is no basis for “Hinduism.” Similarly, the name ‘India’ did not come from any Indian language or culture. So let’s find out their origin.
Origin of the word Hindu
Most scholars feel that the word “Hindu” was developed by outsiders, invaders who could not pronounce the name of the Sindhu River properly. Sindhu was the original name for a great river in north-west India. When invaders from Persia came across this river, they pronounced it ‘Hindu’. Because in Persian, the ‘S’ is pronounced as ‘H’. Eventually from ‘Hindu’, the second ‘h’ disappeared. So from ‘Sindhu’ the word ‘Hindu’ evolved. It described a geographical area. Today the word ‘Hindu’ represents people who follow Sanatan Dharma (Eternal religion based on Vedic knowledge). However later, it became to represent the people of ‘Hindu’ – Sthan. ‘Sthan’ means land. From this evolved the word ‘Hindustan’. It is very important to mention that word Hindustan does not mean only the land of Hindus but all the people of India who live east of the Sindhu River, which is called Hindustan or Bharat.
Origin of the word India
Some sources report that it was Alexander the Great who first renamed the River Sindhu as the Indu, dropping the beginning “S”, thus making it easier for the Greeks to pronounce. This became known as the Indus. This was when Alexander invaded India around 325 B.C. His Macedonian forces thereafter called the land east of the Indus as India, a name more frequently used especially during the British regime.
Thereafter, even the Indians conformed to these standards as set by those in power and used the names Hindu, Hindustan and India. Otherwise, the word has no meaning except for those who place value on it or now use it out of convenience.
Some other names of India
Aryavrata - Land of Aryans
Ajnabh khand - Named on the king Aj - Grandfather of Lord Ram
Hindustan – As discussed above from the word Sindhu
Hind - Short form of Hindustan - First used by Netajee
Bharat – Named on the king Bharat – Official Hindi name
India – Name mostly used by British - Official English name
Friday, October 27, 2006
Types of Karma
Thus, Karma refers to
- Any act or deed
- The principle of cause and effect
- A consequence or "fruit of action” or "after effect" which sooner or later returns upon the doer. What we sow, we shall reap in this or future lives
The concept of Karma is central in Hinduism, Sikhism, Buddhism and Jainism. Breathing, thinking, talking, seeing, hearing, eating, etc., are Karmas. Thinking is mental Karma. Karma is the sum total of our acts both in the present life and in the preceding lives.
The innumerable Karmic Seeds we produce by our various actions - desire, aversion, love, hatred, happiness, etc. will undoubtedly produce, sooner or later, a positive or negative result according to the nature of the seed, if not in this life, then in some future one.
All living creatures are bound to perform some act or Karma. Even if someone decides not to do anything, in reality an act is being performed in form of doing nothing and hence its result will be accordingly.
Types of Karma?
Karma can be divided in three parts:
1. Sanchita Karma (Acquired Karma): In Sanskrit it means – “The accumulated consequence of an individual’s actions in present and past lives.” This is the storage of all karma or sum of all karmas which can be referred as total cosmic debt, in which every moment either an individual is adding or reducing Karma.
Following five aspects of our life are governed by Sanchita Karma :
1. Birth, place of birth and our parents
2. Education and line of education
3. Wealth and source of wealth
4. Longevity and illnesses
5. Death, place of death and mode of death
This karma also refers to the psychological, mental subconscious tendency which determines the propensities for psychological and physical illnesses, particular kinds of obstacles, and a natural habit or tendency to behave in particular way. For example, you have no control over your birth or death but it happens based on your Karma. As time passes Sanchita Karma takes the form of Prarabhada Karma and yields its results. It is very complex to predict that which Karma will yield exactly what result but as a general rule of thumb “As you sow so shall you reap.”
2. Prarabdha Karma (Present Karma) – In Sanskrit it means – “Action that has been unleashed or aroused.” It also refers to the action which manifests now. This is the portion of Sanchita Karma which was earned in the past and it is already in action now. This Karma you can not erase, you have to go through it, because it is already in process. You have no freedom to make any changes to it. This is already yielding the result and thus we have no control to make any changes.
3. Agami Karma (Approaching Karma): In Sanskrit it means –“Actions that has to come.” The Karma or the actions that are now going to be done which will give their results later in future. Some of Agami Karmas bear fruit in the current life; others are stored for future births in form of Sanchita Karma.
There is a freedom in choosing an action here but Agami Karma is influenced by our old tendencies and habits from Sanchita Karma and Prarabdha Karma. If an indivisual is fully aware of his actions he can choose the good Karma which will yield the good result in future.
Some of the following aspects of our life are governed by Agami Karma :
1. Growth of Wealth
2. Growth of Knowledge
3. Social life
4. Marriage
5. Children
Mode of Karma
There are mainly three ways an indivisual performs Karma. You perform your acts or deeds every moment in your life through following ways
1. Manasa - Mind
2. Vaachaa - Speech
3. Karmana - Actions
Can we erase our Karma?
Karma is infinite. Every habit is sort of Karma. Each Karma has a limited time bound affect. The result can be good or bad based on an individual's perception. Being aware of the tendencies may help to overcome the tendencies. But, Karma which has already yielded the result or in process of yielding the result can not be changed or erased. It means Prarabdha Karma is inevitable and should be suffered and endured.
Spiritual Masters say, you can erase your Sanchita Karma through spiritual practices - prayer, meditation and selfless service. And, Agami Karma can be erased through awareness. Only a meditative state of mind does not incur any Karma; and it becomes a witness of every act without any entanglement.
Thus, Karma can be erased only by knowledge (not the information) in form of awareness and spiritual practices, which helps us to make right choices when we act.
What if we do not erase?
As most of us do. Either we do not care what we do or due to lack of awareness or ego stay in the trap of the vicious cycle of Karma. Some part of Agami Karma becomes Sanchitra Karma for future. Then, portion of Sanchita Karma becomes Prarabdha Karma and starts yielding the result and at the same time we perform new actions towards Agami Karma and thus we are forced into the cycle of birth and death till we pay all the dues of our total cosmic debt.
Why some good people face bad things in their life?
A person may be very good from all his acts in present life, but you never know what he did in his previous life (lives).
Saturday, October 21, 2006
Understanding 3-Tier vs. 3-Layer Architecture
The terms tier and layer are frequently used interchangeably, but actually there is a difference between them: Tiers indicate a physical separation of components, which may mean different assemblies such as DLL, EXE etc on the same server or multiple servers; but layers refers to a logical separation of components, such as having distinct namespaces and classes for the Database Access Layer (DAL), Business Logic Layer (BLL) and User Interface Layer (UIL). Therefore, tier is about physical separation and units of deployment, and layers are about logical separation and units of design.
Creating a multi tier project design is more suitable and advisable to mid to large-size projects, whereas a good multi-layered design is suitable for small to mid-size projects.
Let’s understand this difference more closely with my earlier posts on “Developing 3 Tier Application in .NET 2.0”. In reality this example is 3-layer architecture because all the layers are logically separated but stay in one code. Following are the namespaces of each layer
1. Vishwa.Example.Data
2. Vishwa.Example.Business
3. Vishwa.Example.WebSite1
The final DLL contains all the above layers: Vishwa.Example.WebSite1
Now, let’s think how to build the same project in true 3-tier architecture. For simple understanding, each layer will be moved to a separate project and thus creating following three dlls. These dlls can stay on the same machine or different servers.
1. Vishwa.Example.Data.dll --- see Data Transfer Objects (DTO) - Data Access Layer
2. Vishwa.Example.Business.dll --- see Data Transfer Objects (DTO) - Business Layer
3. Vishwa.Example.WebSite1.dll -- Now you can refer the above new dlls to perform the same operation
But, by just moving the code of each layer into a separate project will not work, because first and foremost issue is: each layer depends on other layer, so you can not compile one project without other one and here you are in catch 22 situation.
So you will require changes into current design. Also, if you are not planning to keep all the layers in the same folder of your application, then another big issue- how to refer and communicate with each layer’s object. Here is some approach you can take for each layer to convert into a tier model.You must be wondering why did I use the word 3-Tier instead of 3-layer?
- Literally, create a separate project for each layer.
- For Database Access Layer and Business Logic Layer ASP.NET Web Services or .NET Remoting can be used. If you can use .NET 3.0 Windows Communication Foundation (WCF) Services, that will be great, they seem to me like Web Services but more powerful, secure and flexible than Web Services.
- User Interface Layer will stay as ASP.NET Web Site but some changes will be required for invoking or calling Business Objects. However, existing BLL and DAL layers will be removed from current project.
- Additionally, I will recommend using Microsoft Enterprise Library - Application Blocks for .NET 2.0. This library can help you to build a robust application, it provides solutions to common development challenges such as data access, logging and user interface etc. You can find more information at http://msdn.microsoft.com/practices
- By using (Web) Services, you will move one step towards Service Oriented Architecture (SOA), which is becoming more popular now in enterprise application development.
First of all most of the time people are searching on key words like 3-Tier rather 3-Layer. Word 3-tier architecture is most frequently used but heavily misused in IT industry. So it is easier to bring people to the information they are looking for and then educate them as what exactly it means.
Needless to say that it was easier for me to take a simple example for 3- layer architecture design and explain each layer step by step. Developing a true multi tier approach may look like over killing of the sample project. I may write one sometime in future:).
Wednesday, October 18, 2006
Developing 3-Tier Application in .NET 2.0 – Part 3
In this section, I will connect Business Logic Layer (BLL) to Data Access Layer and then User Interface Layer (UIL) to Business Logic Layer (BLL).
Note: If you are developing an enterprise application please see my next article on “Understanding 3-Tier vs. 3-Layer Architecture”.Business Logic Layer Code
Namespace: Vishwa.Example.Business
Customer.vb : This class will communicate with previously designed Data Access Layer (DAL) in Part -2.' Author : Vishwa
' Date : 10/15/2006
' Class : Customer Business Object
' Design Pattern: Domain Model and Identity Field
' Purpose: This class will act as Business Object and Business Logic Layer
Imports Vishwa.Example.Data
Namespace Vishwa.Example.Business
Public Class CustomerPrivate _custID As Integer = 0Private _custName As String = String.EmptyPrivate _custDOB As DateTime = DateTime.MinValuePrivate _custAddress As String = String.EmptyPrivate _dateCreated As DateTime = DateTime.NowPrivate _dateModified As DateTime = DateTime.Now#Region "Constructor"Public Sub New()End Sub#End Region
#Region "Properties"Public Property CustID() As IntegerGet
Return _custID
End GetSet(ByVal value As Int32)_custID = valueEnd SetEnd PropertyPublic Property CustName() As StringGet
Return _custName
End GetSet(ByVal value As String)_custName = valueEnd SetEnd PropertyPublic Property CustDOB() As DateTimeGet
Return _custDOB
End GetSet(ByVal value As DateTime)_custDOB = valueEnd SetEnd PropertyPublic Property CustAddress() As StringGet
Return _custAddress
End GetSet(ByVal value As String)_custAddress = valueEnd SetEnd PropertyPublic Property DateCreated() As DateTimeGet
Return _dateCreated
End GetSet(ByVal value As DateTime)_dateCreated = valueEnd SetEnd PropertyPublic Property DateModified() As DateTimeGet
Return _dateModified
End GetSet(ByVal value As DateTime)_dateModified = valueEnd SetEnd Property#End Region
#Region "--Customer Object Functions--- "Public Shared Function GetCustomer(ByVal custID As Integer) As CustomerReturn DataAccess.GetCustomers(custID)
End FunctionPublic Shared Function GetAllCustomer() As Generic.List(Of Customer)Return DataAccess.GetAllCustomers()
End FunctionPublic Shared Function AddCustomer() As IntegerDim custInfo As New CustomercustInfo.CustID = 0custInfo.CustName = "unknown"
custInfo.CustDOB = #1/1/1900#custInfo.CustAddress = "unknown"
Return DataAccess.InsertCustomer(custInfo)
End FunctionPublic Shared Function AddCustomer(ByVal custInfo As Customer) As IntegerReturn DataAccess.InsertCustomer(custInfo)
End FunctionPublic Shared Function UpdateCustomer(ByVal custInfo As Customer) As IntegerReturn DataAccess.UpdateCustomer(custInfo)
End FunctionPublic Shared Function DeleteCustomer(ByVal custInfo As Customer) As IntegerReturn DataAccess.DeleteCustomer(custInfo)
End Function#End Region
End ClassEnd Namespace
Now, we have Database, Data Access Layer(DAL) and Business Logic Layer (BLL) ready for last step - User Interface Layer (UIL).
User Interface Layer (UIL)
Namespace: Vishwa.Example.WebSite1
Let's add a Web Form in the Project and drop a GridView Control and Object Data Source Control on this page and make sure that you have following code in the Source.
Customer.Aspx
-----------------------------------------------------------------
Code Snippet
- <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Customer.aspx.vb" Inherits="Vishwa.Example.WebSite1.Customer" %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" >
- <head id="Head1" runat="server" >
- <title>Customer</title>
- </head>
- <body>
- <form id="frmCustomer" runat="server">
- <div style="text-align:center">
- <h2 >Customer Maintenance</h2>
- <asp:LinkButton ID="lnkAddNew" runat="server" Text="Add New" OnClick="InsertBlankRecord" EnableViewState="false" />
- <asp:GridView ID="gdvCustomer" DataKeyNames="CustID" runat="server" AllowPaging="True" DataSourceID="odsCustomer" >
- <Columns>
- <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
- </Columns>
- <EmptyDataTemplate>
- No Customer Record Found.
- </EmptyDataTemplate>
- </asp:GridView>
- </div>
- <asp:ObjectDataSource ID="odsCustomer" runat="server" DataObjectTypeName="Vishwa.Example.Business.Customer"
- DeleteMethod="DeleteCustomer" SelectMethod="GetAllCustomer"
- TypeName="Vishwa.Example.Business.Customer" UpdateMethod="UpdateCustomer">
- </asp:ObjectDataSource>
- </form>
- </body>
- </html>
--------------------------------------------------------------------------
Code File: Customer.Aspx.vb
--------------------------------------------------------------------------Option Explicit OnOption Strict On' Author : Vishwa@VishwaMohan.Com
' Date : 10/15/2006
' Class : Customer
' Purpose: To Get,Insert, Update and Delete Customer Record
Namespace Vishwa.Example.WebSite1
Partial Class Customer
Inherits System.Web.UI.Page
Public Sub InsertBlankRecord(ByVal sender As Object, ByVal e As System.EventArgs)Vishwa.Example.Business.Customer.AddCustomer()gdvCustomer.DataBind()End SubEnd ClassEnd NamespaceCode is complete now. Select Customer.aspx page in Project and Press F5 button (run). You will see the customer page as :
Case 1 : No Record.
Case 2: Click on Add New Link and a Blank new record with default value will be addedCase 3: Click on Edit link and enter a desired value for customer name and address and then click on Update link to update the record.Case 4: Updated record is shown below. You can delete this record by clicking on Delete link. The record will be deleted and you will see the same screen presented in Case 1.
I hope this simple example helped you to understand and implement a 3 tier architecture using Visual Studio.NET 2005. If you have any questions or comments, please feel free to post and I will try to answer them.Once you are able to understand these layer now, let's review the real information in next post.