odd problem with a file my app is creating. Stays 'in use'

A

AussieRules

Hi,

I have a process that writes an image file out to disk.
I reuse the same file name over and over, as there is only every one file
required. THe problem is that when this code executes for the second time,
the file.delete errors with

The process cannot access the file 'file' becuase it is being used by
another process.

Should the close I have at the end of my close, not do this ?

After this code, a picturebox1 is set to point to this filename. On the
closing of that form with the picture box I have a dispose method, which I
figured woulld release the file as well. Seems not, or my dispose technique
is a bit wrong.

any tips on this one

Thanks



If File.Exists(filename) Then

File.Delete(filename)

End If

Dim PictureCol As Integer = 0 ' the column # of the BLOB field

Dim cmd As New SqlCommand("SELECT image FROM tbl_image WHERE image_id =" &
intImageID, SqlConnection)

Try

Dim dr As SqlDataReader = cmd.ExecuteReader()

dr.Read()

Dim b(dr.GetBytes(PictureCol, 0, Nothing, 0, Integer.MaxValue) - 1) As Byte

dr.GetBytes(PictureCol, 0, b, 0, b.Length)

dr.Close()



Dim fs As New System.IO.FileStream(filename, IO.FileMode.Create,
IO.FileAccess.Write)

fs.Write(b, 0, b.Length)

fs.Flush()

fs.Close()

Application.DoEvents()

Catch

MsgBox(Err.Description)

End Try
 
C

Cor

Hi Aussie,

I see also no strange things, but why till the time somebody sees it narrow
your try block, one for the read and one for the write.

Just a guess

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top