Sandip's Programming Zen

An attempt to share tech/coding experiences

Archive for February 2009

SQL Performance and Recovery Model

leave a comment »

Recently I had a case where an application which was working fine suddenly started slowing down and apparently there were no code changes made. After checking around at Database properties found that Recovery Model was set to “Full”. In fact it was not needed according to the backup policy as only full backup was scheduled, not at the level of transaction log.

Setting the Recovery Model to “Simple” solved the problem and application was back on acceptable performance.

Check this link to know more about Recovery Model :
http://msdn.microsoft.com/en-us/library/aa173531.aspx

Written by Sandip

February 18, 2009 at 12:58 pm

Posted in MS SQL

“Length Required” in Firefox with AJAX POST

with one comment

I have a code which makes Ajax post using JQuery in asp.net. It worked fine in IE and Chrome but failed in Firefox. When debugged using Firebug it showed 411 “Lenght Required” error. After wasting couple of hours on google it finally turned out a kind of Jquery bug.

Normally I wrote code like:

    $.ajax({ type: “POST”,
        url: “URL”,
        dataType: “xml”,
        processData: true,
        error: function(XMLHttpRequest, textStatus, errorThrown) {},
        success: {}
    });

Looks normal and works in IE and Chrome but not in FF, to make work in FF we have to provide an empty data header like below:

    $.ajax({ type: “POST”,
        url: “URL”,
        dataType: “xml”,
        data:{},
        processData: true,
        error: function(XMLHttpRequest, textStatus, errorThrown) {},
        success: {}
    });

It is weird because there are so many other headers which we don’t pass it too and they are taken with default values and why not with data header.

Hope it will be solved in upcoming jquery releases and till then hope this helps.

Written by Sandip

February 14, 2009 at 12:53 pm

Posted in Troubleshooting

Vertically Align content in div tag

leave a comment »

I needed to align content bottom-up for one web-based IM interface, searched around but could not find a perfect solution after a while, so here is how I solved the problem:

<div style="height:400px;width:100%">

 <table style="border:0;height:400px;width:100%;overflow:scroll">

            <tr>

            <td  id="TableInner" style="vertical-align:bottom;">

            </td>

            </tr>

          </table>

</div>

In above code, key is to put a table inside a div. Vertical-Align does not work on div tag so no matter what style you apply it will never work. by default it will align top. by putting same Size of table inside div we create another container for our content. Now we can apply vertical-align:bottom to TD tag of our table. Whatever content we need to put now we put it inside that TD tag. problem solved.   The outer div around table provides the scrollbars to our content if it overflows.

In addition if you need to set scroll position of Div to bottom then following Javascript will do that:

var objScr = document.getElementById(‘myDiv’); 

objScr.scrollTop = objScr.scrollHeight;

 

Hope this helps.

Written by Sandip

February 13, 2009 at 1:55 am

Posted in Troubleshooting

Solution: Request format is unrecognized for URL unexpectedly ending in

leave a comment »

You may get this error while calling your web service. In my case it was running perfectly under IIS7 and when deployed on IIS6 it started giving this error.  After searching a while I found that I have to enable GET and POST protocols in web.config file.

Check out the MS article on this. It says it applies on Framework 1.1 but it is still relevent in case of Framework 2.0 +

http://support.microsoft.com/kb/819267

Hope this helps

Written by Sandip

February 7, 2009 at 3:32 am

Posted in Uncategorized

MVC on IIS6 and older

leave a comment »

Older versions of IIS than IIS7 are not going to recognize MVC urls and there for you need to do a work around solution provided by mvc framework itself.

Need to do two things:

1. Register the .mvc extension in IIS by running following script found under your MVC installation folder:

C:\Program Files\Microsoft ASP.NET\ASP.NET MVC RC\Scripts\iismap.vbs

Note: if you are still using preview version then it might not be there.

2. Change your Global.asax file so that mvc urls can now be used with .mvc extensions:

routes.MapRoute(
"Default",                                              // Route name
"{controller}.mvc/{action}/{id}",                           // URL with parameters
new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
);

Note the that we are adding .mvc after controller name. So your URL may look like http://yourdomain/controller.mvc/viewpage

Hope this helps.

Written by Sandip

February 7, 2009 at 3:21 am

Posted in MVC