Re: Filestream Error...
- From: "Tim" <tim@xxxxxxxx>
- Date: Mon, 12 Sep 2005 13:34:29 -0400
Thanks for your reply Jon, I really appreciated it. What do you mean by "You
should, however, definitely use a using statement for your database
connection"?
Thanks
Tim
"Jon Skeet [C# MVP]" <skeet@xxxxxxxxx> wrote in message
news:MPG.1d8fc61a8c4a7a298c6cd@xxxxxxxxxxxxxxxxxxxxxxx
> Tim <tim@xxxxxxxx> wrote:
>> I have a list of products in with images stored in a SQL Server 2000 DB.
>> I
>> need to be able to retrieve the images when a product is chose. I use the
>> code below to get the image from the DB and assign it to the picture box.
>>
>> It works fine the first time but subsequent times it gives me an error
>> saying that the file is in use by another process. What process? If I go
>> to
>> the folder and try to delete the file in windows I get the same error.
>> Can
>> anyone help me here? What am I doing wrong? I am closing the filestream
>> so
>> what is still open?
>
> It doesn't really mean another process - it's a misleading error
> message.
>
> Although you're closing the FileStream, you're then using
> Image.FromFile, which opens another FileStream and keeps it open until
> the image is disposed.
>
> Using a MemoryStream as Jan suggested should solve the problem, but you
> shouldn't use a using block - the image "owns" the stream you pass into
> it, and expects you to leave it open. From the Bitmap constructor docs:
>
> <quote>
> Remarks
> You must keep the stream open for the lifetime of the Bitmap object.
> </quote>
>
> You should, however, definitely use a using statement for your database
> connection :)
>
> --
> Jon Skeet - <skeet@xxxxxxxxx>
> http://www.pobox.com/~skeet
> If replying to the group, please do not mail me too
.
- Follow-Ups:
- Re: Filestream Error...
- From: Jon Skeet [C# MVP]
- Re: Filestream Error...
- References:
- Filestream Error...
- From: Tim
- Re: Filestream Error...
- From: Jon Skeet [C# MVP]
- Filestream Error...
- Prev by Date: Re: Google is now doing what I need to...No Border
- Next by Date: Re: VS.Net debugger?
- Previous by thread: Re: Filestream Error...
- Next by thread: Re: Filestream Error...
- Index(es):
Relevant Pages
|