problem using backgroundworker

threeo

Member
Joined
May 26, 2010
Messages
15
Programming Experience
1-3
i have an app that allows a user to upload a file to a database. then, in the background, i want to move the file to a different folder.
i am trying to use a background worker to do the file move but i always run into this error:

the process cannot access the file because it is being used by another process.

so i'm guessing it is still doing the file read/upload to the database (it works fine for really small files)

how can i do the move once the upload is complete?

i tried putting the actual upload piece in a background worker but it gives me an error saying the filename can't be null even though i check it and it isn't null.
 
the code.....

well, the "dowork" piece is simply:

File.Move(strFileToUploadNameAndDirectory, strNewLocation)

that's it (strFileToUploadNameAndDirectory and strNewLocation are global variables)

now, before this is called, i upload the file to the database:
i use a stored procedure with some parameters:

.Parameters.AddWithValue("@Doc_Extension", "pdf")
.Parameters.AddWithValue("@Last_Update_User", txtUserName.Text)

execute it:
drMember = .ExecuteReader
End With

then close the connection (and set some labels, buttons etc):
prmConnection.Close()
lblUploadMessage.Visible = True
btnUploadFile.Enabled = False
strFileToUploadNameAndDirectory = strFullName
strFileToUploadNameOnly = strFileName

and then run the background worker:
BackgroundWorker1.RunWorkerAsync()

remember, this works fine for really small files

so what must be happening is......it is still in the process of uploading the file to the database when it tries to move the file inside the backgroundworker
how can i fix this?
 
First up, there's nothing in what you've posted that indicates that the file itself is being stored in the database. Second, why are you calling ExecuteReader when you don't appear to be reading anything? Instead of disjointed bits of code, how about you post all the relevant code and use formatting tags so it's readable?
 
Back
Top