Results 1 to 11 of 11

Thread: Allowing Multiple people

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    200

    Exclamation Allowing Multiple people

    I'm developing an application that interfaces with a database to allow multiple users to select multiple items from an Access database using ADO DB. However, whenever there are multiple users I get a "Run-time Error 339: A File is missing or is invalid". This error happens whenever a form loads and the code for that for is:

    VB Code:
    1. '*FORM_LOAD()******************************************************************
    2. 'NAME: Form_Load()
    3. 'DESC: Initially loads the listbox (lstFirstScreen) with the available data
    4. '      from the database
    5. Private Sub Form_Load()
    6.     cmdSelect.Enabled = False
    7.     lblTopTabs.Caption = "PICKSL" & "     " _
    8.                        & " DFC" & "           " _
    9.                        & "PROD" & "        " _
    10.                        & "DESC"
    11.    
    12.     cmdPrint.Visible = False
    13.     cmdPrint.Enabled = False
    14.    
    15.     Set connection = New ADODB.connection
    16.     connection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    17.         "Data Source= G:\Finance\Inventory Control\CycleCount\DB\cycleCount.mdb"
    18.     connection.Open
    19.    
    20.     Set newConnection = New ADODB.connection
    21.     newConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    22.         "Data Source= G:\Finance\Inventory Control\CycleCount\DB\cycleCount.mdb"
    23.     newConnection.Open
    24.    
    25.     Set recordSet = New ADODB.recordSet
    26.     Set newRecordSet = New ADODB.recordSet
    27.      
    28.     Dim inAlterTable As Boolean
    29.     Dim selectStatement As String
    30.     Dim newSelectStatement As String
    31.    
    32.     selectStatement = "SELECT DISTINCT PICKSL,DFP,PROD,DESC FROM [MAIN]"
    33.     newSelectStatement = "SELECT * FROM [ALTER] WHERE TYPEOFCHANGE='SELECTED'"
    34.        
    35.     recordSet.Open selectStatement, connection, adOpenKeyset, adLockPessimistic, adCmdText
    36.     newRecordSet.Open newSelectStatement, newConnection, adOpenKeyset, adLockPessimistic, adCmdText
    37.    
    38.     recordSet.MoveFirst
    39.            
    40.     Do Until recordSet.EOF
    41.         If (newRecordSet.EOF <> True) Then
    42.             newRecordSet.MoveFirst
    43.         End If
    44.         inAlterTable = False
    45.         Do Until newRecordSet.EOF
    46.             If (recordSet.Fields("PICKSL") = newRecordSet.Fields("PICKSL") And _
    47.                 recordSet.Fields("DFP") = newRecordSet.Fields("DFP") And _
    48.                 recordSet.Fields("PROD") = newRecordSet.Fields("PROD") And _
    49.                 recordSet.Fields("DESC") = newRecordSet.Fields("DESC")) Then
    50.                 inAlterTable = True
    51.             End If
    52.             DoEvents
    53.             newRecordSet.MoveNext
    54.         Loop
    55.  
    56.         If (inAlterTable = False) Then
    57.             lstFirstScreen.AddItem (recordSet.Fields("PICKSL") & vbTab _
    58.                 & recordSet.Fields("DFP") & vbTab _
    59.                 & recordSet.Fields("PROD") & vbTab _
    60.                 & recordSet.Fields("Desc"))
    61.         End If
    62.         DoEvents
    63.                
    64.         recordSet.MoveNext
    65.     Loop
    66.    
    67.     recordSet.Close
    68.     connection.Close
    69.     Set recordSet = Nothing
    70.     Set connection = Nothing
    71.    
    72.     If (lstFirstScreen.ListCount > 0) Then
    73.         cmdSelect.Enabled = True
    74.     End If
    75.    
    76. End Sub
    77. '*ENDOF*FORM_LOAD()************************************************************

    I do have a pessimistic lock on the database; could that be what is causing it. And if so I can I keep users from getting the same data at the same time? Any help you be greatly appreciated.

    Nenio foriras ĝis ĝi havas instru ni kiu ni devas scii.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Allowing Multiple people

    A couple of questions:
    Quote Originally Posted by manofsteel00
    whenever there are multiple users I get a "Run-time Error 339: A File is missing or is invalid".
    Does this mean that you do not get this error if only one person is using it? Two? Three? Have you noticed any consistency between the number of users and the occurrance of this error?

    Do you know on what line of code this error is being generated from?

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Allowing Multiple people

    You only need one connection, so remove one of those, and use the same for both recordsets. (it may be causing the problem)

    Next up, why is there no "Exit Do" after the "inAlterTable = True" line? (you currently loop when there is no need!). You should then run "newRecordSet.MoveFirst" every time.

    Also, you do not need two recordsets for this - just use one with SQL that joins the tables appropriately, eg:
    Code:
    SELECT DISTINCT m.PICKSL, m.DFP, m.PROD, m.DESC 
    FROM [MAIN] m 
    LEFT JOIN [ALTER] a
    ON (a.PICKSL = m.PICKSL AND a.DFP = m.DFP AND a.PROD = m.PROD AND a.DESC = m.DESC)
    WHERE (a.TYPEOFCHANGE <> 'SELECTED') 
    OR (a.PICKSL Is Null)
    edit: oops, this should be the SQL I think:
    Code:
    SELECT DISTINCT m.PICKSL, m.DFP, m.PROD, m.DESC 
    FROM [MAIN] m 
    WHERE Not Exists(
      SELECT * 
      FROM [ALTER] a 
      WHERE a.PICKSL = m.PICKSL 
      AND a.DFP = m.DFP 
      AND a.PROD = m.PROD 
      AND a.DESC = m.DESC
      )

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    200

    Re: Allowing Multiple people

    I only get the error when two or more people are accessing the database.

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Allowing Multiple people

    Quote Originally Posted by manofsteel00
    I only get the error when two or more people are accessing the database.
    Did you make the changes suggested by si_the_geek?

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    200

    Re: Allowing Multiple people

    Made the changes, but haven't been able to test it just yet. One quick question though: Would the SQL statement be the same if I wanted to connect to a table in another database or would I need to create another connect? Thank you in advance.

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Allowing Multiple people

    It depends on what the DBMS's for each of the databases are (Access/SQL Server/etc).

    If they are both the same, there is usually a way (there are ways I know of for Access and SQL Server).

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    200

    Re: Allowing Multiple people

    All the databases I connect to are Access 2002, so would I need to create two connections to update data from one database to another database?

  9. #9
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Allowing Multiple people

    Here's how to reference tables from other databases (with or without database passwords):
    http://www.vbforums.com/showthread.php?t=382366

    You can use the same syntax as shown there to join a table in one database to a table in another.

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    200

    Re: Allowing Multiple people

    Is there a way to check to see if a database is locked? I think my problem is that the database is locked.

  11. #11
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Allowing Multiple people

    A database would only be locked if it was opened exclusively, and if such is the case then you wouldn't even be able to connect to it is someone else has opened it exclusively, base on your connectionstring you are not opening it exclusively hence it is not being locked...
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

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