Closing database in VB .Net

  • Thread starter Thread starter Vegar Hansen
  • Start date Start date
V

Vegar Hansen

Hello everone.

Can somebody help me?
When I run my code I can read, write to and delete from database, but when I
have done one of these things and try to copy the databasefile from my
folder to an other folder with Windows Explorer the system "hangs up" for a
couple of minutes. It seems like the databasefile is not closed. But after
2 - 3 minutes the system recover, and I can copy the file without any system
"hangups".

This is a problem because when I try to write to or delete from the database
with my program, it seems like the program also "hangs up" and I must wait
2 - 3 minutes till it recover again. Then the changes is stored.

This is the code I use when I try to write to the database:

Dim sSQL As String

Dim connection As String

connection = "provider=Microsoft.JET.OLEDB.4.0;Data
Source=J:\Bestilling.mdb"

sSQL = "INSERT INTO Bestillinger (StudentNummer, DatamaskinType, LeieTid)
VALUES ('" & studentNr & "', '" & typeMaskin & "', '" & leiePeriode & "')"

Dim testConn As New System.Data.OleDb.OleDbConnection(connection)

Dim testCmd As New System.Data.OleDb.OleDbCommand(sSQL, testConn)

Try

testConn.Open()

Catch myExceptions As System.Exception

Console.WriteLine(myExceptions.Message)

End Try

Console.Write("Test", sSQL)

Console.ReadLine()

If testConn.State = ConnectionState.Open Then

Try

testCmd.ExecuteNonQuery()

Catch myExceptions As System.Exception

Console.WriteLine(myExceptions.Message)

Console.ReadLine()

End Try

testConn.Close()

End If
 
¤ Hello everone.
¤
¤ Can somebody help me?
¤ When I run my code I can read, write to and delete from database, but when I
¤ have done one of these things and try to copy the databasefile from my
¤ folder to an other folder with Windows Explorer the system "hangs up" for a
¤ couple of minutes. It seems like the databasefile is not closed. But after
¤ 2 - 3 minutes the system recover, and I can copy the file without any system
¤ "hangups".
¤
¤ This is a problem because when I try to write to or delete from the database
¤ with my program, it seems like the program also "hangs up" and I must wait
¤ 2 - 3 minutes till it recover again. Then the changes is stored.
¤
¤ This is the code I use when I try to write to the database:
¤
¤ Dim sSQL As String
¤
¤ Dim connection As String
¤
¤ connection = "provider=Microsoft.JET.OLEDB.4.0;Data
¤ Source=J:\Bestilling.mdb"
¤
¤ sSQL = "INSERT INTO Bestillinger (StudentNummer, DatamaskinType, LeieTid)
¤ VALUES ('" & studentNr & "', '" & typeMaskin & "', '" & leiePeriode & "')"
¤
¤ Dim testConn As New System.Data.OleDb.OleDbConnection(connection)
¤
¤ Dim testCmd As New System.Data.OleDb.OleDbCommand(sSQL, testConn)
¤
¤ Try
¤
¤ testConn.Open()
¤
¤ Catch myExceptions As System.Exception
¤
¤ Console.WriteLine(myExceptions.Message)
¤
¤ End Try
¤
¤ Console.Write("Test", sSQL)
¤
¤ Console.ReadLine()
¤
¤ If testConn.State = ConnectionState.Open Then
¤
¤ Try
¤
¤ testCmd.ExecuteNonQuery()
¤
¤ Catch myExceptions As System.Exception
¤
¤ Console.WriteLine(myExceptions.Message)
¤
¤ Console.ReadLine()
¤
¤ End Try
¤
¤ testConn.Close()
¤
¤ End If
¤

Is the corresponding .LDB file deleted immediately after closing the Access database?

Not sure if this database is on a network share but this could cause some delay in closing the
database.


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
Back
Top