A Place for C Sharpers/.Netters

I Will do coding till last moment of life-Kiran Patil

Archive for the ‘Uncategorized’ Category

Long-running processes and browser timeout issue (mainly Internet Explorer)?

Posted by kiranpatils on February 26, 2012

Challenge:

This week we faced strange issue [Oh yes, Issues are always strange, that's why we know them as an issue! :-) ].

Basically we were running a long running operation on server and in between our browser displayed “Internet Explorer cannot display the webpage” page. (Needless to say, we are using Internet Explorer)  We checked at our server-side (logs, sql connection, web  server etc.) and everything was perfect! We were clueless whether our server operation got completed or not.

If you are also facing this same issue, then keep reading we have a solution for you!

Solution:

Okay, so we were clueless what to do? Then suddenly it stroked in my mind. As IE shown this error page, why not try the same process with Firefox? [So long back faced similar issue and tried with FF and it worked. But at that time never researched why it worked!]

And you guess what? It worked for us. i.e. the same process got completed without changing anything on server-side code!

Okay, so we were happy as our task got completed. But we were not sure why it worked. [And my colleague Muktesh asked me a question, why it worked?].

Really good question! Then I started my research and found something interesting to share with all of you! Really interesting to read here you go:

Following Stackoverflow thread has some good points on this:

http://stackoverflow.com/questions/633075/browser-timeouts-while-asp-net-application-keeps-running

CAUSE

By design, Internet Explorer imposes a time-out limit for the server to return data. The time-out limit is five minutes for versions 4.0 and 4.01 and is 60 minutes for versions 5.x, 6, and 7. As a result, Internet Explorer does not wait endlessly for the server to come back with data when the server has a problem.

Internet Explorer imposes a time-out limit for the server to return data. By default, the time-out limit is as follows:

Internet Explorer 4.0 and Internet Explorer 4.01 5 minutes
Internet Explorer 5.x and Internet Explorer 6.x 60 minutes
Internet Explorer 7 and Internet Explorer 8 60 minutes

When the server is experiencing a problem, Internet Explorer does not wait endlessly for the server to return data.

Source : http://support.microsoft.com/kb/181050

Proposed Solution: Found some good links which gives some solutions which you can try [Frankly, Haven't tried them on my own, try at your own risk! -- I strongly recommend to use Firefox]

http://intersoftpt.wordpress.com/2009/06/23/resolve-page-cannot-be-displayed-issue-in-ie8/

http://www.ehow.com/how_5943517_control-browser-timeouts-ie-7.html

Now, we know what’s wrong with IE? But now the second question comes up Why it works with Firefox? Don’t worry we have answer for this as well.

Currently, Firefox timeout is determined by the system-level connection establishment timeout [Source : http://kb.mozillazine.org/Network.http.connect.timeout]. It was earlier issue in Firefox as well and they fixed it – https://bugzilla.mozilla.org/show_bug.cgi?id=592284

If you would like to know what your System-level connection is, please refer : http://support.microsoft.com/default.aspx?scid=kb;en-us;314053 [Source: https://bugzilla.mozilla.org/show_bug.cgi?id=142326]

Summary : When you have long running operation running on server and would like to run it from browser and if browser is displaying client side error, Firefox is a good choice!

Other Resources:

http://stackoverflow.com/questions/1192375/timeout-behavior-of-different-browsers

Happy Long running operation! :-)

Posted in Uncategorized | 3 Comments »

2010 in review

Posted by kiranpatils on January 3, 2011

The stats helper monkeys at WordPress.com mulled over how this blog did in 2010, and here’s a high level summary of its overall blog health:

Healthy blog!

The Blog-Health-o-Meter™ reads Wow.

Crunchy numbers

Featured image

About 3 million people visit the Taj Mahal every year. This blog was viewed about 46,000 times in 2010. If it were the Taj Mahal, it would take about 6 days for that many people to see it.

 

In 2010, there were 32 new posts, growing the total archive of this blog to 125 posts. There were 40 pictures uploaded, taking up a total of 7mb. That’s about 3 pictures per month.

The busiest day of the year was November 23rd with 246 views. The most popular post that day was “The underlying connection was closed: The connection was closed unexpectedly.” While returning Data Table from WCF service..

Where did they come from?

The top referring sites in 2010 were google.co.in, forums.asp.net, google.com, consultingblogs.emc.com, and blogs.msdn.com.

Some visitors came searching, mostly for there is no script engine for file extension .vbs, there was an error while trying to serialize parameter, c multiple inheritance, and svn: can’t create tunnel: the system cannot find the file specified..

Attractions in 2010

These are the posts and pages that got the most views in 2010.

1

“The underlying connection was closed: The connection was closed unexpectedly.” While returning Data Table from WCF service. September 2008
12 comments

2

Hosting a WCF Service in IIS 7.0 September 2008
3 comments

3

IF…else with Eval is not supported+GridView+ASP.NET March 2008
4 comments

4

Checking Execution Time with C#.NET+ Use of it In WSSF+WCSF February 2008
1 comment

5

svn: Can’t create tunnel: The system cannot find the path specified. August 2009
2 comments

See you in 2011!

Thanks for flying with kiranpatils.WordPress.com in 2010.
I look forward to serving you again in 2011! Happy New Year!

Wish you a happy new year and happy coding! :-)

Posted in Uncategorized | 1 Comment »

Session values lost when any exception occurs

Posted by kiranpatils on November 10, 2010

Challenge

If you’ve stored some values in session and your session values getting lost when any exception occurs. Then this article may provide you hint to solve it.

Solution

In my case the reason was as below:

Basically I was creating a directory under my web root directory and when any exception occurred I was deleting that directory. And that was the main reason for losing my session values.

So, Now I am creating/deleting directory outside my web root directory and problem is solved!

And deepest reason is Application Restart – Whenever any directory gets created/deleted under web root ASP.NET restarts the application pool. To read more about ASP.NET Application restart read my blog post.

Happy Coding! :-)

directory

 

Posted in Uncategorized | Leave a Comment »

Create PerfMon WebPage

Posted by kiranpatils on November 10, 2010

Challenge

If you’ve used PerfMon – tool from microsoft for performance monitor. [if you haven’t then it is really good to use tool for monitoring your application’s performance once It is deployed on server. Try it today!].

While monitoring performance we need to run perfmon tool [START | RUN | perfmon]. But what if admins need to view it from web browser and it can be from anywhere.

Solution

Here’s the solution for that. We can configure perfmon to run inside a webpage [But you need IE!].

Step by step guide is here: http://www.myitforum.com/inc/arts/9435MMC%20to%20webpage.doc

Reference : http://www.myitforum.com/articles/15/view.asp?id=7407

Happy Performance Monitoring! :)

Posted in Uncategorized | Leave a Comment »

Merging two XML files in to one dataset

Posted by kiranpatils on November 10, 2010

Challenge:

Since so long back one of my best buddy Devang asked me that how can we merge two Datasets in one. In short, suppose you’ve two XML Files and you want to read them in different dataset. So, obviously they both will belong to two different data sets. But you would like to have both of them in a single dataset. How can you do it?

Before you see the solution code. Let’s see the problem by code


private const string FILE1_PATH = "~/Books1.xml";
private const string FILE2_PATH = "~/Books2.xml";
protected void Page_Load(object sender, EventArgs e)
{
// Read First Xml
DataSet dataSet1 = new DataSet();
dataSet1.ReadXml(Server.MapPath(FILE1_PATH));

// Read Second Xml
DataSet dataSet2 = new DataSet();
dataSet2.ReadXml(Server.MapPath(FILE2_PATH));

// Merge -- Will not work
dataSet1.Merge(dataSet2);

// Read in Table -- Will not work
dataSet1.Tables[0].ReadXml(Server.MapPath((FILE1_PATH)));
dataSet2.Tables[0].ReadXml(Server.MapPath((FILE2_PATH)));

// Merge DataSet2.Table in first dataset -- WILL NOT WORK -- DataTable already belongs to another DataSet.
dataSet1.Tables.Add(dataSet2.Tables[0]);
}

Solution

When we try to use following line.

// Merge DataSet2.Table in first dataset -- WILL NOT WORK -- DataTable already belongs to another DataSet.
dataSet1.Tables.Add(dataSet2.Tables[0]);

It will throw following error:

DataTable already belongs to another DataSet.

System.ArgumentException was unhandled by user code
Message=”DataTable already belongs to another DataSet.”
Source=”System.Data”
StackTrace:
at System.Data.DataTableCollection.BaseAdd(DataTable table)
at System.Data.DataTableCollection.Add(DataTable table)
at _Default.Page_Load(Object sender, EventArgs e) in c:\TestHarness\MergeTwoXmlFiles\Default.aspx.cs:line 35
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException:

Reason fort an error is dataset2′s Table number 0 can’t be added to dataset1′s tables collection as it is already in dataset2′s tables collection — Recall Reference types?

So, final solution is as below:

</pre>
// Remove table from second dataset
DataTable dt = dataSet2.Tables[0];
dataSet2.Tables.Remove(dt);
// and add it to first one
dataSet1.Tables.Add(dt);

Happy Dataset Merging! :-)

Posted in Uncategorized | 1 Comment »

Adding Assembly in to GAC-Progrmmatically

Posted by kiranpatils on June 26, 2010

How To Add Assembly in GAC(Global Assembly Cache) Programmatically?

In my last project I need to ad Assembly to GAC…you will tell go to Microsoft .Net Configuration tool and Add Assembly to GAC….i also know this i am not that much dump…But i need to add it programmatically….now you also have to think na???? But i have its solution so don’t worry just follow this Post..

First i think u know that what it requires to add an assembly to GAC..What??????You don’t…….no worries yaar Main Hoon na…

For Adding an Assembly to GAC…your assembly should have strong name…what???you don’t know how to make an assembly which contains strong name….i am going to be a Mad now you don’t know anything… anyways i will guide you to do that so no worries.

Just Have to follow 3 Steps:

Step 1: Open .NET Framework SDK Command Prompt. and Type sn- k <keyname>.snk

Strong NAme01

This will generate a Key at current path. In Above’s examples(C:\).

Step 2. Now Add this Strong name to your solution by right click on solution and Add an Existing Item and locate Key File.

Strng Name 02

Step 3: Now Open AssemblyInfo.CS/Vb file and add [assembly: AssemblyKeyFile("key.snk")] this line.

Strong name03

That’s it now your Assembly have a Strong name and it is ready to be add in GAC..

Its easy na????

Now my main Aim comes tht how to add assembly to GAC programmatically.

It is also easy.Just follow me.

1. Add Reference to System.Enterpriseservices.

2. It has Publish Class make its object:

Publish publish = new Publish();
3. And now you can Install it into using this:

publish.GacInstall(<Path of your Assembly to Add in GAC>);

you can show a openFileDialog to user from it user can select an Assembly and based on FilePath Property you can add it into GAC..and Magic it is going to be added in GAC..user will Be happy!!![and that's what a developer wants..am i right?].

Just by following 3 Steps your assembly is in to GAC..is it good na???

But there is one problem in it..can you guess what???No na..ok let me tell you.

See if Assembly dosen’t contains Strong Name than it will not show any error and not add it in to GAC Also..end user will not come in to know about it any time…so now what to do??? I have developed one Helper Class which will check that Assembly has strong name or not, user has permission to Add Assembly in to GAC etc.

So here is my Helper Class:


<em><strong>public class Helper
{
public enum ErrorMessage
{
None,   //NO ERROR
Unknown,    //NOT IDENTIFIED ERROR OCCURED
AssemblyNotFound, //Assembly can't be found
AssemblyLoadError,  //Error during loading assembly
NotCLRAssembly, //Specified Assembly is Not a CLR Assembly
NotSignedAssembly, //NOT ASSIGNED STRONG NAME
NotAuthorized   //Security Exception</strong></em>

<em><strong> } </strong></em>

<em><strong> public static ErrorMessage InstallAssembly(String assemblyPath)
{
if (String.IsNullOrEmpty(assemblyPath))
return ErrorMessage.AssemblyNotFound;
try
{</strong></em>

<em><strong>Assembly assembly = Assembly.ReflectionOnlyLoadFrom(assemblyPath);
byte[] pkey = assembly.GetName().GetPublicKeyToken();
if (pkey.Length == 0) return ErrorMessage.NotSignedAssembly;</strong></em>

<em><strong>}
catch (BadImageFormatException)
{
return ErrorMessage.NotCLRAssembly;
}
catch (FileLoadException)
{
return ErrorMessage.AssemblyLoadError;
}
catch (FileNotFoundException)
{
return ErrorMessage.AssemblyNotFound;
}
catch (SecurityException)
{
return ErrorMessage.NotAuthorized;
}
Publish publish = new Publish();</strong></em>

<em><strong>try
{
publish.GacInstall(assemblyPath.Trim());
return ErrorMessage.None;
}
catch (SecurityException)
{
return ErrorMessage.NotAuthorized;
}
} </strong></em>

<span style="color: #ff00ff;"> }</span>

To use it:


<em><strong> private bool InstallAssembly()
{
String AssemblyPath = assemblyofd.FileName;</strong></em>

<em><strong> OpenFileDialog assemblyofd = new OpenFileDialog();
bool installed = false;
if (!string.IsNullOrEmpty(AssemblyPath))
{
Helper.ErrorMessage ErrMsg = Helper.InstallAssembly(AssemblyPath);
switch(ErrMsg)
{
case Helper.ErrorMessage.None:
//MessageBox.Show("The assembly you specify is successfully installed into the GAC", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
installed = true;
break;</strong></em>

<em><strong> case Helper.ErrorMessage.AssemblyLoadError:
MessageBox.Show("Some problem occured During Loading an Assembly,Please Try Later",  "Cannot Add Assembly", MessageBoxButtons.OK, MessageBoxIcon.Error);
installed = false;
break;
case Helper.ErrorMessage.AssemblyNotFound:
MessageBox.Show("Sorry, Unable to Find Assembly", "Cannot Add Assembly", MessageBoxButtons.OK, MessageBoxIcon.Error);
installed = false;
break;
case Helper.ErrorMessage.NotAuthorized:
MessageBox.Show("You are not authorized to install Assembly, please Contact your Administrator", "Cannot Add Assembly", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
installed = false;
break;
case Helper.ErrorMessage.NotCLRAssembly:
MessageBox.Show("The assembly you specify is not a managed assembly", "Cannot Add Assembly", MessageBoxButtons.OK, MessageBoxIcon.Error);
installed = false;
break;
case Helper.ErrorMessage.NotSignedAssembly:
MessageBox.Show("Unable to add the selcted assembly. The assembly must have a strong name (name,versioan and public key).", "Cannot Add Assembly", MessageBoxButtons.OK, MessageBoxIcon.Error);
installed = false;
break;
case Helper.ErrorMessage.Unknown:
MessageBox.Show("Some problem occured during Installing Assembly", "Cannot Add Assembly", MessageBoxButtons.OK, MessageBoxIcon.Error);
installed = false;
break;
}
}
return installed;
}</strong></em>

That’s it.

This will serve the Purpose.

Try it and let me know it works for you or not.

“If you do your best whatever happens will be for the best”.

Posted in Uncategorized | Leave a Comment »

There is no script engine for file extension “.vbs”

Posted by kiranpatils on August 13, 2009

Challenge:

If you received an error saying There is no script engine for file extension “.vbs” then you are on right post :)

Solution:

I tried doing this : regsvr32 %systemroot%\system32\vbscript.dll

http://www.technologystory.net/2009/02/25/windows-vista-tips-there-is-no-script-engine-for-file-extension-vbs/

But like you — for me too no luck :(

But finally following trick worked for me :)

1. Locate the file %windir%\inf\wsh.inf (inf is a hidden
folder)

2.right click and select “Install”.

Happy Coding!!

Posted in Uncategorized | 31 Comments »

.NET Framework Common Namespaces and Types Poster

Posted by kiranpatils on May 30, 2009

Background:

This post is dedicated to guys who do believe in OOPS or eager to learn OOPS Concepts[Like me :) ].  Our .NET F/w is built heavily on OOPS concepts. So, if you see take any Class like System.Web.UI.WebControls.TextBox if you see it’s CD and dig more in it you will learn a lot:

image 

This is just one example if you take any Control/Class of .NET F/W you will understand more how it has been designed and why?

So it is always good to have all namespace and types poster with you always too look at it while you are having cup of coffee :)

 Framework Version

Download Link

3.5 http://www.microsoft.com/downloadS/details.aspx?familyid=7B645F3A-6D22-4548-A0D8-C2A27E1917F8&displaylang=en
2.0 http://blogs.msdn.com/photos/brada/images/524537/original.aspx

 

So, Grab this and take a print out of it and have fun :)

Programming With Fun!!

Posted in .NET, Uncategorized | Tagged: , | Leave a Comment »

IE innerHTML – "Unknown runtime error"

Posted by kiranpatils on October 24, 2008

Setting value of <div id=”divhtml”> using js like this :

document.getElementById(“divhtml”).innerHTML = “<form><input type=”text”>…</form>”;

it was giving me error..

Solution:

oldDiv = document.getElementById(divhtml);
newDiv = document.createElement(oldDiv.tagName);
newDiv.id = oldDiv.id;
newDiv.className = oldDiv.className;
newDiv.innerHTML = “<form><input type=”text”>…</form>”;

oldDiv.parentNode.replaceChild(newDiv, oldDiv);

And it worked like a charm!!!!!!

Link : http://piecesofrakesh.blogspot.com/2007/02/ies-unknown-runtime-error-when-using.html

Posted in Uncategorized | 1 Comment »

Adding application relative path in head section of master Page for JavaScript

Posted by kiranpatils on October 20, 2008

Problem:

I have my application structure similar to as shown below:

image

My JavaScript file has one function which I want to use on each and every page which used my master page. That JS function looks like:


</font>
<font size="2">function HelloWorld()
{
&nbsp;&nbsp;&nbsp; alert("Helloo.....World...");
}</font>
<font size="2">
And to register a JS file i have registered it on one place which is in MASTER..rather than registering it on each and every page. so my master head looks like this:


</font>
<font size="2">
<head runat="server">&nbsp;&nbsp;&nbsp; </font> 

<font size="2"><script language="javascript" type="text/javascript" src="Javascript/HelloWorld.js">
</script>
</head></font>
<font size="2">

on FormWithMasterPage.aspx. i was calling that function as shown below:


</font>
<font size="2"><asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;
<input type="button" value="OK" onclick="HelloWorld();" />
</asp:Content></font>
<font size="2">

And it was working as expected..means showing alert message:

image

but when i tried the same within SubPageDefault.aspx which is under my SubFolder folder it was throwing an error:

image

Which says that it was unable to find JS function HelloWorld();

In short..How to Add application relative Javascript reference?????

Because for SubPageDefault.aspx function it was trying to find “Javascript/HelloWorld.js” under /SubFolder/javascript/..

Solution:

To solve this problem you need to change bit in your master page head section:

1. Open master page and locate its <HEAD> Section and if it has runat=”server” remove it. [In some case if you are using Themes then it is compulsory to put it..no problem put another head tag with no runat="server".]

2. Hook the code as shown below under <HEAD> for registering JS:


</font>

<font size="2">
<head>&nbsp;&nbsp;&nbsp;
</font><font size="2">
<font color="#0000ff">&nbsp;&nbsp;&nbsp;
<%--To use line as shown below remove runat="server" And if it is required to put runat="server" put one more head with runat="server"--%>
&nbsp;&nbsp;&nbsp;
<script language="javascript" type="text/javascript" src='<%=ResolveClientUrl("~/Javascript/HelloWorld.js")%>'></script></font>
&nbsp;&nbsp;&nbsp; </font>
<font size="2"><font color="#ff0000"><%--Line below will not work--%>
&nbsp;&nbsp;&nbsp;
 <%--<script language="javascript" type="text/javascript" src="Javascript/HelloWorld.js"></script>--%>
</font></head></font>
<font size="2">

That’s it…Happy mastering!!

Source code: http://sites.google.com/site/klpatils/Home/RelativeJSURL.rar?attredirects=0

Links:

http://www.dotnetgenerics.com/Modules/TricksAndTips/ASP.NET/PowerOfTilda.aspx

http://www.odetocode.com/Articles/419.aspx

http://www.odetocode.com/articles/450.aspx – ATOZ of Master Page

Posted in Uncategorized | Leave a Comment »

 
Follow

Get every new post delivered to your Inbox.

Join 102 other followers