Can not log on locally to as user x with virtual directory password

If you look close at the error, it will say
Module : IIS Web Core

This means it is coming from IIS. The problem is you do not have permission to access the config file. The error actually quotes config file as well, esp the line that says


Go to the location where your config file is located. The IIS should give you that location in the error message. Right click in the folder and check directory permission. See what permission user ‘x’ has. In my case, somehow it has a cross sign on top of it. I dont know how it happened. It was working fine. Note that IIS is configured to access the site (and hence the location) via user ‘x’.

Fix ASP.NET Menu Layout Issue in Chrome and Safari

I had this menu issue which would not render properly in Chrome and Safari but run ok in Internet Explore and FireFox. The following is the fix. Put the following code at the top of your Page_load() function of the page where the issue exists.

/* Fix the Chrome and Safari Menu layout issue (ASP) */
if (Request.UserAgent.IndexOf("AppleWebKit") > 0)

I copied this originally from somewhere. Can’t seem to find it.

Reading null values from datatabase in C# code

If you tried reading a null value from the database such as a null date, you might have across this exception

Specified cast is not valid

Casting Nullable Values

The following code works unless a null datetime is returned. Note that DateTime is followed by ? which means this date can accept a null value therefore nullabe.

/* assume nullable datetime in the database */
DateTime? exportDate = null;
exportDate = (DateTime)cmd.ExecuteScalar();

This is a little bit strange that you cannot use DateTime? operator to cast the return value as a nullable datetime. Although you can use it and it will not give you error, it does not give you the required result. That is it does not cast null values. To cast null values you must use As Operator.

Use As Operator with Nullable values

To case a nullable value, you must use As operator in C#. Also you must return the datetime as nullable field. The following is the correct version of the above code, which failed to return null values.

/* assum nullable datetime in the database */
DateTime? exportDate = null;
exportDate = cmd.ExecuteScalar() as DateTime?;

Condition on null does not work with =

What do you expect from the following code? Will the block inside if be executed?

IF ( @ID != NULL )
      UPDATE inventory
      SET    count = 5
      WHERE  id = @ID

The statments inside If will never be executed because it will always evaluate false. The reason it equal (=) operator is not compatible with NULL. To compare NULL value, use IS operator. To fix the above we can write

      UPDATE inventory
      SET    count = 5
      WHERE  id = @ID

Or we can use ISNULL operator to convert NULL into a value

IF ( Isnull(@ID, 0) = 0 )
      UPDATE inventory
      SET    count = 5
      WHERE  id = @ID

Object reference not set to an instance of an object.

How to troubleshoot Object reference not set to an instance of an object in C#.

Put a break point in the code, execute the code
Inspect the value where you are getting this error

Inspect the value you are assigning to a variable/object or inspect the object itself that is being assigned the value

open the watch1 widow (Dubug>Windows>Watch>Watch1), type in the variable exactly as it appears in code with the dot.  Are you getting a value for the field?
Are you getting nullreference exception instead? If so there is where the exception is coming from.

It is possible that are you fetching the value from the wrong place or you are assigning a value to something that does not exists.

Database Vendor code: 229 – Crystal Report

If you get the below error in Crystal Report

Failed to retrieve data from the database. Details: [Database Vendor Code: 229]

This mean you do not have access to the data. This possibly occurred because you created your report on one machine and then deployed it on another. On deployment, you noticed that your report does not pull that data instead you get this error. The most likely cause is the permission. You do not have permission to query that data or run stored procedures or function.

Possible Causes

  • Your report uses functions calls or store procedure, your login is not allowed to run function and stored procedures
  • Your login does not have select permission for the database/table
  • Other permission related problem


By allowing read or execute permission will fix the problem. If it is just one one function call /store procedure that is causing the problem, the following command will be helpful

GRANT EXECUTE ON dbo.my_function TO [user/role]

Force GridView to Refresh in ASP.NET

You can force gridview to referesh its data by calling GridViews.DataBind() function in the code behind.

I have also come across a couple of others solutions that does the same. The one that works best is to use databind() on gridview

This is the most elegant solution. As an example, lets say you have a GridView that displays data from a table. You have another FormView that inserts data into the gridview. If you insert the data from FormView, you will notice that gridview does not updates the data. To fix this, select the FormView, go to properties, create the ItemInserted event for the form and put this code in it

This will cause the gridview to refresh. As soon as you add the data, Gridview will automatically display it. What actually happens is, DataBind() forces page fresh. When page is reloaded, it reloads the new data while it maintains its present state. Everything is so fast you don’t seem to notice it.

Other Solutions

Someone has commented that you have to call databind on both SQLDataSource and the gridview to refresh data as follows

In my case I confirmed, binding on datasoruce is not needed at least in this case.

Yet another Solution

This was a problematic solution. It caused my delete in gridview not work. Don’t know why exactly was so, May be I put it in the wrong function but it did work after refreshing the gridview.

Weird ASP Bug – Gridview update does not work if there is somethign in page_load function

In my Gridview, select, insert, delete all were working properly but not Update. Found out that my code in Page_load() was causing this not to work. I removed the code from page load where I as updating the Gridview. The update started working again.

What is weird is there was no error and no indication where the problem was. You have to hunt all possible avenues to hunt for the error.

Weird ASP.NET Error – Insert does not work in FormView in ASP.NET

You have a FormView and an Insert Template inside it, if you put the insert template fields in an ASP.NET table for better formatting, the insert function will not work. This is very weird. In the above example, the fields in table … will not work. The culprit here is runat=”server”. If you remove this, the insert works.

... rows and cells

This is quite a weird error in ASP.NET. But the following works

wordpress theme not displaying properly

You just installed a wordpress theme and when you activated it (or even previewed it), it does not show properly. It takes the whole page, there is only html contents, no formatting is applied. This happened to me when I installed my new template. Interesting it worked on my local system but did not work on my public domain.

I troubleshooted this using Firefox Developer Plugin. If you have already installed it, you can right click in the page, in the popup menu go to Web Developer > CSS > View CSS

This will show all your CSS files in the page. In my case I had 403 (Permission denied in front of style.css)

So I went to the directory and checked the permission. Indeed it was set to 0600 while it should have been 0644. I click on 0600 and changed it to 0644 (I had to do it twice, the first time it did not work), and my theme was displaying properly.