03 December, 2011

Could not access network location %SystemDrive%\inetpub\wwwroot\”

I have found the message - Could not access network location %SystemDrive%\inetpub\wwwroot\” - When I was trying to install Infragistic NetAdvantage on Windows 7. To solve the problem do the followings.

1. Type "regedit" in the Run From Start Menu dialog box to open the "Registry Editor".
2. Find the following key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\InetStp\PathWWWRoot
3. Change the value of this registry key from "%SystemDrive%\inetpub\wwwroot" or " \inetpub\wwwroot\" to "C:\inetpub\wwwroot". If your default website in IIS is instead stored in a different location, set the value of this registry key to that path instead.

Then install your software.

30 September, 2011

Object reference not set to an instance of an object.

Server Error in '/' Application.

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

The source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL:

1. Add a "Debug=true" directive at the top of the file that generated the error. Example:

<%@ Page Language="C#" Debug="true" %>


2) Add the following section to the configuration file of your application:

                                                     < compiler language="C#;Csharp"                 extension=".cs"                  type="Microsoft.CSharp.CSharpCodeProvider,system, Version=1.0.5000.0,  Culture=neutral, PublicKeyToken=b77a5c561934e089" />                    ""                                                                                                                                  

Note that this second technique will cause all files within a given application to be compiled in debug mode. The first technique will cause only that particular file to be compiled in debug mode.

Important: Running applications in debug mode does incur a memory/performance overhead. You should make sure that an application has debugging disabled before deploying into production scenario.

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.] 
System.Web.UI.Control.UnloadRecursive(Boolean dispose) +168
System.Web.UI.Control.UnloadRecursive(Boolean dispose) +175
System.Web.UI.Control.UnloadRecursive(Boolean dispose) +175
System.Web.UI.Page.UnloadRecursive(Boolean dispose) +23
System.Web.UI.Page.ProcessRequestCleanup() +43
System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +253
System.Web.UI.Page.ProcessRequest() +78
System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21
System.Web.UI.Page.ProcessRequest(HttpContext context) +49
ASP.post_aspx.ProcessRequest(HttpContext context) +4
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +100
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75

How to find the size of all tables in SQL Server database

SQL Server gives you everything its stored procedure sp_spaceused. Unfortunately this SP does not support iterating over all tables in a database, so we needed to leverage another (undocumented) Stored Procedure sp_msForEachTable.



-- Find DB size.
EXEC sp_spaceused

-- Create a table to counts row and sizes.
[name] NVARCHAR(128),
[rows] CHAR(11),
reserved VARCHAR(18),
data VARCHAR(18),
index_size VARCHAR(18),
unused VARCHAR(18)

INSERT #tbl EXEC sp_msForEachTable 'EXEC sp_spaceused ''?'''


-- # of rows.
SELECT SUM(CAST([rows] AS int)) AS [rows]
FROM #tbl


After executing this, you will get the size of all tables in your database.

01 May, 2011

How to release port 80

Few days ago, I fall in a problem. I could not start apache server by XAMP control panel. There was a message shown port 80 busy. However ultimately, I found the solution this was due to IIS server. IIS Server was running on port 80 at that time.

Here is the step by step procedure, how I release port 80

1. Go to command prompt.
2. Check which process is using port 80
  • On the command prompt window, type the following command.

    netstat -o -n -a | findstr 0.0:80

  • You will see the following screen

The last column is process Id column

Open Task Manager to check the process ID
  1. Right click on the taskbar to open the the task manager.
  2. Go to the Processes tab.
  3. Click the View menu
  4. And make sure you select the PID (Process Identifier) as shown in the image below.
Now you can see which process is using which PID and description like the following.


Stop the services

  1. Go to Task Manager.
  2. Click the Services tab
  3. Arrange the Services by description or by
  4. For IIS I found Service name as IIS Admin
  5. Right click on it and select Stop Sevice.

25 February, 2011

Solution disappears in solution explorer : Visual Studio 2010

I installed visual studio 2010 in my pc. I created a blank solution. When ever I add a project to the solution the original i.e root solution is disappear. This means that as soon as you add a project to a blank solution, the solution disappears and you are unable to add another project. I spent a lot of time to solve the problem. It is very easy.

To do this, goto tools->options->Projects and Solution and check the "Always show solution" option.

10 January, 2011

Global variable of ASP.net

Global variables are those variables that can be accessed anywhere in the application. Global variable should always be used with caution. It stores data. The most common way of accessing global variables in ASP.net are by using Application, Cache, and Session Objects.

- Application objects are application level global variables, that need to be shared for all user sessions. Thus, data specific to a user should'nt be saved in application objects. While using application objects, the objects are locked so that multiple page requests cannot access a specific application object. Below is a code example for usage of application object...

Application("UserData") = "dotnetuncle";

//DestinationPage.aspx gets the value from the Application State
String sString = Application("UserData").ToString();

Cache - The cache object is similar to the application object in scope, however, it does not need any explicit locking and unlocking. Code below shows usage of Cache object...

Cache("Userdata") = "dotnetuncle";

//Destination.aspx retrieves the value from Cache object

String sString = Cache("Userdate").ToString();

The cache object also shares data across all user sessions. The cache object has features like it can automatically expire cached content after specified time periods or once memory consumption has reached a maximum.

- The session object is used to store the data specific to a user for the entire length of a user's visit to a website. Below is a code that shows usage of the session object in ASP.NET ...

//InitialPage.aspx stores the user’s credentials in Session state
Session("UserName") = txtUserName.Text;

//DestinationPage.aspx gets the user’s name from Session state

String sString = Session("UserName").ToString();

ASP.NET stores session values in the server memory. If there are plenty of active user's of a website, then the memory consumption on the server increases by leaps. Because of this reason, large websites use very less Session Variables. Session state can be configured to be automatically stored in a SQL Server database, or it can be configured to be stored centrally in a state server within a server farm. By default, a user’s session ends 20 minutes after their last page request and their data goes out of scope, freeing it from memory. In case user information is to be tracked by a large website, then a oookie is preferred.

Cookie - A cookie is a piece of data that is stored on a user's browser. Thus, a cookie does not use any server memory.