Results 1 to 2 of 2

Thread: RC6: Memory-Cn visibility problem

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2017
    Posts
    761

    Question RC6: Memory-Cn visibility problem

    Hello!

    I would like to ask if it matters if the cConnection is created in the main process or if I can have a function in an activex dll that looks like this:


    Code:
    Public Function NewMemDB(ByVal uName As String, ByVal uEncKey As String, uOutConnection As cConnection, uError As String) As Boolean
    
        
    Dim iLine&
    iLine = 1
    go_start:
    On Error GoTo ErrHandler
    
    
        Dim sb As IStringBuilder
        Set sb = NewStringBuilder
    
        
        sb.Append "file:" & uName      ' ->  file:drivescanner
        sb.Append "?"                   '? is query-indicator  
        sb.Append "mode=memory"        '  ->  file:drivescanner?mode=memory
        sb.Append "&"                  '& ist parameter-trenner ->  file:drivescanner?mode=memory&
        sb.Append "cache=shared"       '  ->  file:drivescanner?mode=memory&cache=shared
    
        Dim s$
        s = sb.ToString
    
        Set uOutConnection = New_c.Connection(s, DBCreateInMemory)
        
        uOutConnection.CreateNewDB s, uEncKey
    
        uOutConnection.ExecCmd "PRAGMA read_uncommitted=1"  'allow the Client, to "see" even the uncommitted inserts, the thread will perform
        uOutConnection.Execute "PRAGMA journal_mode=off"  'these settings will increase the Insert-Performance a bit
        uOutConnection.Synchronous = False
    
        NewMemDB = True
        
    Exit Function
    ErrHandler:
    uError = "Error " & Err.Number & " (" & Err.Description & ") in procedure " & Quote("NewMemDB") & " of " & Quote("modobjects.bas") & ", Line: " & iLine
    On Error GoTo -1
    Debug.Assert False
    End Function
    The reason why I am asking if that I create a cconnection exactely the same from the main thread and from a threaded dll, and the cconnection is created using yet another an activex dll, and for some reason, there kind of a "timing problem": When I press Pause in the IDE at some point of time, the main thread can suddenly "see" the cconnection and the records that the threaded lib inserted.
    But I have not found out the problem behind it.

    This weird "trip" over an additional activex dll is part of my self-disciplining to resolve circular dependencies.

    ps: I should perhaps also mention that I use 2 memory-cns at the same time using different names. I am not sure if that is part of the problem.
    ps2: Since I remove the 2 other memory cns, it seems to work fine.
    ps3: Nope, that was not the problem..

    I am currently suspecting that this function in my activex dll is not well placed there:

    Code:
    Public Function CreateTH(byval uTaskname as string) as cthreadhandler
       set CreateTh=SomeLogicToEstablishIDAndPathForTheDll(uTaskname)
    End Function
    Thank you.
    Last edited by tmighty2; May 6th, 2026 at 12:43 AM.

  2. #2
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,454

    Re: RC6: Memory-Cn visibility problem

    Quote Originally Posted by tmighty2 View Post
    The reason why I am asking if that I create a cconnection exactely the same from the main thread and from a threaded dll, and the cconnection is created using yet another an activex dll, and for some reason, there kind of a "timing problem": When I press Pause in the IDE at some point of time, the main thread can suddenly "see" the cconnection and the records that the threaded lib inserted.
    But I have not found out the problem behind it.
    With such a shared MemDB, you can instantiate a separate cConnection in the main, as well as in each (STA)-thread.
    All these separate Connection-Objects then share the same MemDB-allocation - and can "read/write" into it -
    (as long as the same virtual file-name is used: as e.g. file:drivescanner?mode=memory&cache=shared)

    Your above "problem" (the main-thread can read data, which other AX-Dll-Threads have written into the MemDB,
    is exactly "what one tries to achieve" with such a setup... (data-sharing in a mem-area, conveniently accessible from each thread).

    Please describe in more detail, what you're trying to accomplish...

    Olaf

Tags for this Thread

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