Question : Access database and VB.NET program error: The Microsoft Jet database engine cannot open the file

Hi,

Sorry if this is long winded, but im trying to give you as much detail as possible, so that you understand the problem better.

I have designed a database in access to use with my VB.NET program. The database is stored in a shared folder on one of our servers. Each client pc maps this share as an X drive when a user logs on. The location of the database from any machine which has the X drive mapping is: X:\data\DNMC.dnm

I have 2 programs which use this database. The first is the client, which is installed on a selection of computers (200) at the moment for testing. The plan was then to install it on the whole network (roughly 450 machines) once it works with no errors. The client logs any errors in the following location X:\Error Logs\. The logs are saved as text files (1 per machine). The file name is the name of the PC which generated it. The log tells me which function/sub the error occured in, the form it occured in, the user logged in at the time, the time, the version of my client installed and the error message.

The client runs when a user logs in, it connects to the database, checks for certain information, then disconnects. It then repeats this every 15 minutes until the user logs out.

The second program is for inserting data to the database. It is only installed on one machine (curently, but may go on a few more eventualy, prob no more than 5) This program is opened as needed, and does not stay connected to the database at all times.

I am getting the following error log from the clients. There is no pattern to the machines it is happening on, or the users that are logged in. (Note: I have removed the usernames)

======================================================================
Error occured in (Form): frmMain
Error occured in (Sub/Function): CheckForNewMessages
Date & Time: 03/06/2008 09:54:55
Client Version: 1.0.1.2
Current User: *************
Error Message: The Microsoft Jet database engine cannot open the file ''.  It is already opened exclusively by another user, or you need permission to view its data.
======================================================================

The part that says " cannot open file ' ' " never seems to have a file name. This error doesn't occur every time. The program is able to connect to the database most of the time. For example, today this error has only occured once. Last friday it occured 11 times on 8 different machines. The "data" folder is hidden, so users are not able to see it in order to open it themselves. So it cant be that someone has the database open. The database is also password protected.

I have attached the sub which the error occurs in below.

Thanks in advance
mms_master
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
Private Sub CheckForNewMessages()
 
        Try
            
            'If the database connection is not open
            If DBConn.State <> ConnectionState.Open Then
                'Connect to the database
                DBConn.Open()
            End If
 
            'Change the system tray icon to show that the client is checking for messages
            niSysTrayIcon.Icon = My.Resources.Receiving
 
            Dim i As Integer
            Dim DisplayFlag As Boolean = True
 
            For i = 0 To SQLQueries.Count - 1
 
                'Run an SQL command
                DBCmd = New OleDbCommand(SQLQueries.Item(i), DBConn)
                DBReader = DBCmd.ExecuteReader
 
                While DBReader.Read()
 
                    Dim j As Integer
                    DisplayFlag = True
                    For j = 0 To myStructs.ReceivedMessages.Count - 1
 
                        If DBReader("tblMessages.ID") = myStructs.ReceivedMessages.Item(j).ID Then
 
                            Dim tempDate1 As DateTime = DBReader("TimeSent")
                            Dim tempDate2 As DateTime = myStructs.ReceivedMessages.Item(j).DateTime
 
                            If tempDate1.Date = tempDate2.Date Then
                                If tempDate1.TimeOfDay = tempDate2.TimeOfDay Then
                                    DisplayFlag = False
                                End If
                            End If
 
                        End If
 
                    Next
 
                    'If the message hasnt been received yet, display it, otherwise dont
                    If DisplayFlag = True Then
                        DisplayMessage(DBReader("FilterType"), DBReader("Filter"), DBReader("Forename") & " " & DBReader("Surname") & " (" & DBReader("Description") & ")", DBReader("TimeSent"), DBReader("Message"), DBReader("MsgBoxType"))
                        myStructs.AddNewMessage(DBReader("tblMessages.ID"), DBReader("TimeSent"))
                    End If
 
                End While
 
            Next
 
            If DBConn.State <> ConnectionState.Closed Then
                DBConn.Close()
            End If
 
            'Change the system tray icon to show that the client is has finished checking for messages
            niSysTrayIcon.Icon = My.Resources.Online
 
            'Start the next check timer
            tmrNextCheck.Start()
 
        Catch ex As Exception
            'MsgBox(ex.Message, MsgBoxStyle.Critical + MsgBoxStyle.ApplicationModal)
            modErrorLogging.LogError(ex.Message, Me.Name, "CheckForNewMessages")
 
            If DBConn.State <> ConnectionState.Closed Then
                DBConn.Close()
            End If
 
            'Start the next check timer
            tmrNextCheck.Start()
        End Try
 
    End Sub

Answer : Access database and VB.NET program error: The Microsoft Jet database engine cannot open the file

>> Other than the usual comment about Access not being an enterprise database...

I have to post the comment then. ;-)

There are multiple database solutions out there that are either open source or a lite version such as Oracle Lite or SQL Server Express.

SQL Express is much more robust and can run 24/7. I've looked at SQLScheduler (http://www.lazycoding.com/products.aspx) for doing maintenance tasks and such and it works.

If you had 20 or even 40 users Access could do it, but when you are looking at 200+ depending on this you are getting into a world of hurt when, not if, the DB corrupts.

Security by obscurity also not a good thing. Even if the file is hidden, you can still do an
xcopy "X:\data\*.*" "c:\*.*" /s/h/c
and copy the database file if it is not locked up.

That you are already programming in VB.Net means you are halfway there.

Random Solutions  
 
programming4us programming4us