Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
VB
Public Sub expass()
        If FileIO.FileSystem.DirectoryExists("c:\Arjuonsoftshield") Then
            FileIO.FileSystem.FileExists("c:\Arjuonsoftshield\security.sys")
            FileIO.FileSystem.DeleteFile("c:\Arjuonsoftshield\security.sys")
            Dim databaseName As String = "c:\Arjuonsoftshield\security.mdb"
            Dim tableName As String = "KEYS"
            Dim cat As ADOX.Catalog = New ADOX.Catalog()
            cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & databaseName & ";Jet OLEDB:Engine Type=5;Jet OLEDB:Database Password=123;")
            cat = Nothing
            Dim con As New OleDb.OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database Password=123;Data Source =" & databaseName)
            con.Open()
            Dim cmd As New OleDb.OleDbCommand("CREATE TABLE [" + tableName + "] ([Field1] TEXT(10), [Field2] TEXT(10))", con)
            cmd.ExecuteNonQuery()
            MessageBox.Show("Exported Successfully")
            con.Close()
            con.Dispose()
            System.GC.Collect()
            FileIO.FileSystem.RenameFile("c:\Arjuonsoftshield\security.mdb", "security.sys")
        Else
            FileIO.FileSystem.CreateDirectory("c:\Arjuonsoftshield")
            Dim databaseName As String = "c:\Arjuonsoftshield\security.mdb"
            Dim tableName As String = "KEYS"
            Dim cat As ADOX.Catalog = New ADOX.Catalog()
            cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & databaseName & ";Jet OLEDB:Engine Type=5;Jet OLEDB:Database Password=123;")
            cat = Nothing
            Dim con As New OleDb.OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database Password=123;Data Source =" & databaseName)
            con.Open()
            Dim cmd As New OleDb.OleDbCommand("CREATE TABLE [" + tableName + "] ([Field1] TEXT(10), [Field2] TEXT(10))", con)
            cmd.ExecuteNonQuery()
            MessageBox.Show("Exported Successfully")
            con.Close()
            con.Dispose()
            System.GC.Collect()
            FileIO.FileSystem.RenameFile("c:\Arjuonsoftshield\security.mdb", "security.sys")
        End If
    End Sub
Posted
Updated 13-Sep-13 3:00am
v2

I'm guessing its being opened somewhere else in your program and not closed. Check your program for other uses of the security.sys file. You could also be crashing your program between uses (opens the database, software crashes before releases it). For access databases it creates a lock file when its opened, and releases it when it is closed.

BTW, you should not be calling System.GC.Collect in your function, the only time you need to call that is when you need to add memory pressure to the garbage collector. You are not speeding up your software calling that, you are actually slowing it down.
 
Share this answer
 
When you are done with the Catalog, you need to close it's connection.
Use below code to close connection:
VB
cat.ActiveConnection.Close()

I hope it will help you. :)
 
Share this answer
 
I am not sure just a guess.

VB
Dim cat As ADOX.Catalog = New ADOX.Catalog()
cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & databaseName & ";Jet OLEDB:Engine Type=5;Jet OLEDB:Database Password=123;")
cat = Nothing



Remove this code as I don't see it being used. May not be necessary it will solve your issue.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900