Im trying to move file after reading database file but im getting error that it is being used by another process.
My code
$sDatabasePath=testfile.dat
$sDatabaseConnectionString=[string]::Format("data source={0}",$sDatabasePath)
$oSQLiteDBConnection = New-Object System.Data.SQLite.SQLiteConnection
$oSQLiteDBConnection.ConnectionString = $sDatabaseConnectionString
$oSQLiteDBConnection.open()
$oSQLiteDBCommand=$oSQLiteDBConnection.CreateCommand()
$oSQLiteDBCommand.Commandtext="SELECT * from table_id"
$oSQLiteDBCommand.CommandType = [System.Data.CommandType]::Text
$oDBReader=$oSQLiteDBCommand.ExecuteReader()
while($oDBReader.HasRows)
{
if($oDBReader.Read())
{
$resultName = $oDBReader["name"]
}
}
$oSQLiteDBConnection.close()
Move-Item -Path testfile.dat -Destination /somepath/
I found that it helped for others to add system gc collect but no luck for my code and still throws same error. I just need to close DB connection with releasing file and move file to another location
.Dispose()method for all .NET objects:$oSQLiteDBCommand, $oDBReader, $oSQLiteDBConnection | ForEach-Object Dispose