Results 1 to 13 of 13

Thread: [RESOLVED] ERROR: The process cannot access the file . . .

Threaded View

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046

    [RESOLVED] ERROR: The process cannot access the file . . .

    Well it's been a while. It's awesome to see this place still thriving after all of these years.
    I've got an error I cannot figure out after much online searching. Ive tried all sorts of things but am at a loss.Hoping someone here can help. The error I am getting is this
    mscorlib.dll
    Additional information: The process cannot access the file 'C:\dbfile.mdf' because it is being used by another process.

    I am using Visual Studio 2017 VB.net. My Imports are:
    Code:
    Imports System
    Imports System.IO
    Imports System.IO.Compression
    Imports Microsoft.VisualBasic
    Imports System.Data.OleDb
    Imports System.Data
    Imports System.Data.SqlClient
    The offending code:

    Code:
     ' NOTE THAT I EDITED THE FILENAME DOWN TO SOMETHING SIMPLE. IT ISNT REALLY IN THE ROOT DIR. 
    'I HAVE FULL PERMISSIONS WHERE IT RESIDES AND CAN INDEED COPY/DELETE/ETC IT PROGRAMATICALLY WHERE IT RESIDES
               connectionString = "Data Source=(localdb)\v11.0;Integrated Security=true;AttachDBFileName="C:\dbfile.mdf"
                    connection = New System.Data.SqlClient.SqlConnection(connectionString)
                    connection.Open()
                        queryString = "SELECT * FROM dbo.myTable;"
                        adapter = New SqlDataAdapter(queryString, connection)
                    adapter.UpdateCommand = New SqlCommandBuilder(adapter).GetUpdateCommand()
    
                    runParams = New DataSet()
                        adapter.Fill(RunParams, "RunParams")
                        runParams.Tables(0).Rows(0).Item(3) = 1
                    adapter.Update(runParams, "RunParams")
    
                    connection.Close()
    
                    adapter.UpdateCommand.Dispose()
                    adapter.Dispose()
                        runParams.Dispose()
    
    
                    connection.Dispose()
                    'ALL WORKS PERFECT TO THIS POINT, BUT AFTER THIS POINT, IF I TRY TO DO ANYTHING WITH THE MDF FILE (COPY,MOVE, WHATEVER) I GET THE ERROR
    Last edited by Muddy; Oct 2nd, 2019 at 08:43 AM. Reason: resolved

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width