PC Review


Reply
Thread Tools Rate Thread

Download timeout error

 
 
news.microsoft.com
Guest
Posts: n/a
 
      31st Oct 2005
I experienced the following exception occasionally, which happens when the
program downloads the image data from the Web site. The program first
downloads some bytes successfully, and then waits for 5 minutes. At last, it
reports "The operation has timed-out". I must declare that this problem
doesn't happen in the most cases. The .NET Platform of the client program
and the ASP.NET program are all V1.1.

Who can give me some solutions for it? Thanks in advance.


----------
Exception:
Message: The operation has timed-out.
Source: System
TargetSite: Int32 Read(Byte[], Int32, Int32)
StackTrace:
at System.Net.ConnectStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at RTC7.Image.ViewPictureInRecord.Copy(Stream stream, String filename)
at RTC7.Image.ViewPictureInRecord.LoadImageFromServer(String sUrl),


//-------------
// Codes of the client program to download the image data:
public string LoadImageFromServer(string sUrl)
{
bool isAborted = false;
string strURL_ = sUrl;
string strLocalTmpFile = "";
Stream stream = null;
WebRequest webreq = null;
WebResponse webres = null;
try
{
Uri uri = new Uri(strURL_);

webreq = WebRequest.CreateDefault(uri);

webreq.Timeout = 60000;
webres = webreq.GetResponse();

if(webres != null)
stream = webres.GetResponseStream();
else
return null;
//...
}
catch(Exception ex)
{
// ...
}
finally
{
if(webres != null)
webres.Close();
if(stream != null)
stream.Close();
}
return strLocalTmpFile;
}

public bool Copy(Stream stream, string filename)
{
const int conBufferLeng = 20000;
FileStream fstream= null;
byte[] buffer = new byte[conBufferLeng];
int iByteCountInBuffer = conBufferLeng;
bool blnOkay = false;
try
{
if(stream != null)
{
if(File.Exists(filename) == false)
fstream = File.Create(filename);
else
fstream = File.OpenWrite(filename);
if(fstream != null && fstream.CanWrite == true)
{
if(stream.CanSeek == true)
stream.Position = 0;
do
{
iByteCountInBuffer = stream.Read(buffer,0,conBufferLeng);
fstream.Write(buffer,0,iByteCountInBuffer);
}
while(iByteCountInBuffer > 0);
blnOkay = true;
} // If destination is okay.
} // If source is okay.
}
finally
{
if(fstream != null)
fstream.Close();
buffer = null;
}
return blnOkay;
}


/// <summary>
/// The codes of .NET ASP page to download the image data.
/// </summary>
public class GetPicturePage: System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
const string CSqlSeletImageInf = "select img from IMAGE where sys_ID =
{0}";
try
{
string sID = Request["id"];
string SQLComm = string.Format(CSqlSeletImageInf, sID);

//-------------------------------
// Retrieve the image data from the database.
byte[] img = ImgTool.GetImage(SQLComm);

//--If the img is null, return directly.
if (img == null)
{
return;
}

// In the most cases, the size of the img is 200KB.
// Sometimes, it's 2~3 MB.
// Only in a few cases, it's 20 MB.
Response.ContentType = "image/jpeg";
Response.BinaryWrite(img);
return;
//...
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
finally
{
Response.End();
//...
}
}

//...
}



 
Reply With Quote
 
 
 
 
Jim Underwood
Guest
Posts: n/a
 
      4th Nov 2005
It is possible that the website itself is actually timing out on the
request. In fact, it sounds like that is exactly the error message you are
receiving. If you own the website, you can do some performance tuning to
alleviate this issue. If it is not your website, then I think you are stuck
with the issue. Any time you are connecting to a website there is a chance
your request is going to time out.


"news.microsoft.com" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I experienced the following exception occasionally, which happens when the
> program downloads the image data from the Web site. The program first
> downloads some bytes successfully, and then waits for 5 minutes. At last,

it
> reports "The operation has timed-out". I must declare that this problem
> doesn't happen in the most cases. The .NET Platform of the client program
> and the ASP.NET program are all V1.1.
>
> Who can give me some solutions for it? Thanks in advance.
>
>
> ----------
> Exception:
> Message: The operation has timed-out.
> Source: System
> TargetSite: Int32 Read(Byte[], Int32, Int32)
> StackTrace:
> at System.Net.ConnectStream.Read(Byte[] buffer, Int32 offset, Int32

size)
> at RTC7.Image.ViewPictureInRecord.Copy(Stream stream, String filename)
> at RTC7.Image.ViewPictureInRecord.LoadImageFromServer(String sUrl),
>
>
> //-------------
> // Codes of the client program to download the image data:
> public string LoadImageFromServer(string sUrl)
> {
> bool isAborted = false;
> string strURL_ = sUrl;
> string strLocalTmpFile = "";
> Stream stream = null;
> WebRequest webreq = null;
> WebResponse webres = null;
> try
> {
> Uri uri = new Uri(strURL_);
>
> webreq = WebRequest.CreateDefault(uri);
>
> webreq.Timeout = 60000;
> webres = webreq.GetResponse();
>
> if(webres != null)
> stream = webres.GetResponseStream();
> else
> return null;
> //...
> }
> catch(Exception ex)
> {
> // ...
> }
> finally
> {
> if(webres != null)
> webres.Close();
> if(stream != null)
> stream.Close();
> }
> return strLocalTmpFile;
> }
>
> public bool Copy(Stream stream, string filename)
> {
> const int conBufferLeng = 20000;
> FileStream fstream= null;
> byte[] buffer = new byte[conBufferLeng];
> int iByteCountInBuffer = conBufferLeng;
> bool blnOkay = false;
> try
> {
> if(stream != null)
> {
> if(File.Exists(filename) == false)
> fstream = File.Create(filename);
> else
> fstream = File.OpenWrite(filename);
> if(fstream != null && fstream.CanWrite == true)
> {
> if(stream.CanSeek == true)
> stream.Position = 0;
> do
> {
> iByteCountInBuffer = stream.Read(buffer,0,conBufferLeng);
> fstream.Write(buffer,0,iByteCountInBuffer);
> }
> while(iByteCountInBuffer > 0);
> blnOkay = true;
> } // If destination is okay.
> } // If source is okay.
> }
> finally
> {
> if(fstream != null)
> fstream.Close();
> buffer = null;
> }
> return blnOkay;
> }
>
>
> /// <summary>
> /// The codes of .NET ASP page to download the image data.
> /// </summary>
> public class GetPicturePage: System.Web.UI.Page
> {
> private void Page_Load(object sender, System.EventArgs e)
> {
> const string CSqlSeletImageInf = "select img from IMAGE where sys_ID =
> {0}";
> try
> {
> string sID = Request["id"];
> string SQLComm = string.Format(CSqlSeletImageInf, sID);
>
> //-------------------------------
> // Retrieve the image data from the database.
> byte[] img = ImgTool.GetImage(SQLComm);
>
> //--If the img is null, return directly.
> if (img == null)
> {
> return;
> }
>
> // In the most cases, the size of the img is 200KB.
> // Sometimes, it's 2~3 MB.
> // Only in a few cases, it's 20 MB.
> Response.ContentType = "image/jpeg";
> Response.BinaryWrite(img);
> return;
> //...
> }
> catch (Exception ex)
> {
> Response.Write(ex.ToString());
> }
> finally
> {
> Response.End();
> //...
> }
> }
>
> //...
> }
>
>
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error: Timeout expired. The timeout period elapsed prior to comple michael Microsoft ADO .NET 3 22nd Feb 2009 06:05 PM
Download timeout after ~15 min cburkhar@generac.com Microsoft ASP .NET 2 4th Oct 2007 08:31 PM
Timeout expired error after adding download file code bonita Microsoft ASP .NET 0 28th Feb 2006 09:33 AM
IE FTP Download lost after timeout =?Utf-8?B?UmVjeWNsZU1hbg==?= Windows XP Internet Explorer 2 6th Oct 2005 03:51 AM
another "InvalidOperationException: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool" error Jeff Braun Microsoft ADO .NET 1 30th Jul 2003 12:19 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:06 AM.