Monday, February 20, 2012

How to solve this configuration error while deploying application?

Problem:
I am getting a server error while setting up BugTracker.Net in my local machine.


How can I solve this issue?

 Solution:
This error gives when required .net  framework is not installed on your machine.
To install .net framework go to visual studio 2010  command prompt and write the following command:

aspnet_regiis -i

This will install .net framwork 4 on your machine.


Sunday, February 5, 2012

An alternative to cursor

While working with database we often require to use Cursor. Cursors force the database engine to repeatedly fetch rows. This may slow down your database and locking may occur. As a result cursor are not suggested to use if not extremely necessary.

If there is a primary key on a table, you can usually write a WHILE loop to do the same work without incurring the overhead of a cursor. The following example demonstrate the idea:

Declare @ItemId bigint

Declare @OldItemCode varchar(50)

      SELECT Top 1   @ItemId= ItemId, @OldItemCode=OldItemCode
      FROM         InvItem
      WHERE      (IsStockItem = 'true')

      WHILE @ItemId is not null
      BEGIN
            print 'Item: '+convert(varchar(10),@ItemId)+' - '+convert(varchar(50),@OldItemCode)
            if exists (select ItemId from InvItem where IsStockItem=1 and ItemId>@ItemId)
                  begin
                        SELECT Top 1    @ItemId=ItemId, @OldItemCode=OldItemCode
                        FROM         InvItem
                        WHERE      (IsStockItem = 'true') and ItemId>@ItemId
                  end
                  else
                  begin
                        set @ItemId=null
                  end
      END

Monday, January 30, 2012

How to write data to a CSV file?


The article shows the work of parsing the rows from the dataset into a file stream using a comma delimiter. By loading the data into a dataset, you have access to metadata for the columns. You can retrieve the column name from the metadata when building the row headers for your export file. If the Overwrite parameter is true, then the file will be recreated: otherwise, the data will be appended to the existing file.

public static void CreateCSVFile(DataSet myDs,String FullFilePath, Boolean Overwrite)
{
int i = 0;
int fldCnt = 0;
StreamWriter sw = new StreamWriter(FullFilePath, Overwrite);
fldCnt = myDs.Tables[0].Columns.Count;
//Gather and create csv line for columns
for (int x = 0; x <= fldCnt - 1; x++)
{
sw.Write(“[“ + myDs.Tables[0].Columns[x].ColumnName + “]”);
if (x < fldCnt - 1)
sw.Write(“,”);
}
sw.Write(sw.NewLine);
//Then gather row information into an HTML string
for (int x = 0; x <= myDs.Tables[“TABLE”].Rows.Count - 1; x++)
{
while (i < fldCnt)
{
if (!Convert.IsDBNull(myDs.Tables[“TABLE”].Rows[x][i]))
{
sw.Write(Convert.ToString(myDs.Tables[“TABLE”].Rows[x][i]));
}
if (i < fldCnt - 1)
sw.Write(“,”);
i++;
}
i = 0;
sw.Write(sw.NewLine);
}
sw.Close();
}

Tuesday, November 22, 2011

ASP.Net State management

What is State Management?
State management is the process by which you maintain state and page information over multiple requests for the same or different pages.
ASP.NET includes several options that help you preserve data on both a per-page basis and an application-wide basis.

Types of State Management
There are two basic types of State Management:
1.       Client-Based State Management
2.       Server-Based State Management
Client-Based State Management:
Client based state management techniques stores data on the client in various ways. Client based state management techniques are:
A.      View state
B.      Control state
C.      Hidden fields
D.      Cookies
E.       Query strings
View state:
The view state represents the state of the page when it was last processed on the server. It's used to build a call context and retain values across two successive requests for the same page. By default, the state is persisted on the client using a hidden field added to the page and is restored on the server before the page request is processed.
If the amount of data stored in the ViewState() property exceeds the specified value in the MaxPageStateFieldLength() property, multiple hidden fields are used to store View state data.
                Advantages:     
a)      Server resources not required.
b)      Simple implementation
c)       automatic retention of page and control state
d)      Enhanced security features. The values in view state are hashed, compressed, and encoded for Unicode implementations.
Disadvantages:
a)      Scope is limited to only single page.
b)      Performance. The view state is stored in the page itself, so increase the page size.
c)       Security. The view state is stored in a hidden field on the page. Although view state stores data in a hashed format, it can be tampered with. 
Control state:
If you create a custom control that requires view state to work properly, you should use control state to ensure your control work properly though developers disable view state. The ControlState() property allows you to persist property information that is specific to a control and cannot be turned off like the ViewState() property.
     Advantages:     
a)      Server resources not required.
b)      Reliable. Because control state can not be turned off like ViewState.

Disadvantages:
a)      Some programming is required.
Hidden Fields:
A hidden field acts as a repository for any page-specific information that you want to store directly in the page. ASP.NET allows you to store information in a HiddenField control, which renders as a standard HTML hidden field. A hidden field does not render visibly in the browser.
You must submit the page using an HTTP POST command in order for hidden-field values to be available.

                Advantages:     
a)      Server resources not required.
b)      Simple implementation
c)       Widespread support.
Disadvantages:
a)      Potential security risk.
b)      Performance. The hidden fields are stored in the page itself, so increase the page size.
c)       Does not support rich data types to store.
Cookies:
A cookie is a small amount of data that is stored either in a text file on the client file system or in-memory in the client browser session. Browser sends with cookies values with every page request to the same server. Cookies can be temporary or persistent.

Advantages:     
a)      Server resources not required.
b)      Simple implementation
c)       Configurable expiration rules
d)      Data persistent.
Disadvantages:
e)      Size limitation: Most browsers support maximum 4096 bytes cookies.
f)       User configuration refusal: User can disable cookies in their browser.
g)      Security risk: Can be tempered.  
Query strings:
A query string is information that is appended to the end of a page URL. Query strings provide a simple but limited way to maintain state information.  Some browsers and client devices impose a 2083 character limit on the length of the URL.
You must submit the page using an HTTP POST command in order for query string values to be available.
Advantages:     
h)      Server resources not required.
i)        Simple implementation
j)        Widespread support.
Disadvantages:
k)      Size limitation: Some browser limits 2083 chars on the length of URLs.
l)        Security risk: Information is visible to the user.  
Server-Based State Management:
Server based state management techniques store data in memory on the server.  Server based state management techniques are:
A.      Application state
B.      Session state
C.      Profile Properties
Application state:
Application state provides a method of storing data global to whole application. These data are visible to entire application and shared by all active sessions. That’s why Application state variables are global variables for an ASP.Net application.
Advantages:     
m)    Simple implementation
n)      Application wide scope
Disadvantages:
o)      Application scope in case of Web Garden or Web Firm.
p)      Limited Durability of data.
q)      Requires server memory.
Session state:
Session state provides a method of storing session specific information that is visible only within the session.
Advantages:     
r)       Simple implementation
s)       Session specific events
t)       Data can persists across multiple process
Disadvantages:
u)      Application scope
v)      Limited Durability of data.
w)    Requires server memory