Developer forum

Forum » Feature requests » Move HttpContext in DatabaseConnectionProvider

Move HttpContext in DatabaseConnectionProvider

Anders Ebdrup
Reply

Hi Dynamicweb,

 

We are working on a project with web socket, where we would like to use the database connection from Dynamicweb, but for now the method CreateConnection in DatabaseConnectionProvider has this line:

            Dim strDatabasePath As String = HttpContext.Current.Server.MapPath("\Database\")

Can this be moved 4 lines down and only be accessed if the database type is set to Access? Because web socket has no HttpContext set.

 

Best regards, Anders


Replies

 
Nicolai Høeg Pedersen
Reply
This post has been marked as an answer

Yes of course.

Did that already. In the next hotfix of 8.6.1, TFS#17031

BR Nicolai

Votes for this answer: 1
 
Anders Ebdrup
Reply

Thanks a lot for a quick response! :-)

Next problem is in ContextManager, which searches for a connection provider in the application cache which is also not available when using websockets. Can this be fixed too?

Maybe just fall back to default connection provider if the HttpContext is not set?

 

Best regards, Anders

 
Anders Ebdrup
Reply

The method could be changed to something like this:

 

    Private Shared Function GetDatabaseConnectionProvider() As IDatabaseConnectionProvider

        Dim provider As IDatabaseConnectionProvider = Nothing
        If Not IsolateFromHttpContext Then
            CheckDatabaseConnectionProviderTypesInCache()

            ' Get list from cache.
            Dim databaseConnectionProviders As ArrayList = CType(ContextManager.Cache.Item("DatabaseConnectionProviderTypes"), ArrayList)

            'If it is something
            If Not databaseConnectionProviders Is Nothing Then

                ' Loop Resolver Types
                For Each databaseConnectionProviderType As Type In databaseConnectionProviders
                    provider = CType(Extensibility.AddInManager.CreateAddInInstance(databaseConnectionProviderType), IDatabaseConnectionProvider)
                    Exit For
                Next
            End If
        End If

        ' If cache is empty, revert to default database connection provider.
        If IsNothing(provider) Then
            provider = New DatabaseConnectionProvider()
        End If

        Return provider
    End Function

Best regards, Anders

 
Nicolai Høeg Pedersen
Reply
This post has been marked as an answer

Also changed - on the same TFS#

BR Nicolai

Votes for this answer: 1