Can't get powershell module to work stable

Can't get powershell module to work stable

avatar

I've got some weird behavior - can not create entries\folders or even read data with 100% success rate.
I'm trying to run this simple code (below) from 2 places - OS: Windows Server 2019 Datacenter and Windows 10 LTSB, RDM version is latest in both cases - 2020.2.19.0
Result is the same. Under same user in GUI app from both systems everything works fine.

Code:

Import-Module "${env:ProgramFiles(x86)}\Devolutions\Remote Desktop Manager\RemoteDesktopManager.PowerShellModule.psd1"
$ds = Get-RDMDataSource -Name rdm
Set-RDMCurrentDataSource $ds

$folder_session = Get-RDMSession -GroupName 'ScriptImported' #this folder does exist


Datasource does work, at least according to isconnected and isoffline properties. Its MSSQL server.

PS O:\> Get-RDMCurrentDataSource

ID          : 202c12de-2530-4625-9132-89d9843c36f5
IsConnected : True
IsOffline   : False
Name        : rdm
Type        : SQLServer


Last row returns me Get-RDMSession : Connection not found. Even thought folder with such name does in fact exist.
However.
What's weird about that is once I change anything about that folder in GUI app (folder name, permissions - anything) and run Get-RDMSession -GroupName 'ScriptImported' again - I get giant stacktrace (below) and session object too - so it kind of works. Until I reopen powershell_ise at least. Then in order to 'connect' to folder I need to change something about folder again - even if I switch whatever was changed previously back to initial value - in my tests I switched permissions on said folder between "inherited" and "everyone" back and forth.

PS C:\Users\JenkinsServer> Get-RDMSession -GroupName 'ScriptImported'
Devolutions.RemoteDesktopManager.Business.Exceptions.RootException: Duplicate root creation detected!
   в Devolutions.RemoteDesktopManager.Business.DataSources.DatabaseConnectionDataSource.DetectDuplicateRoots(Connection root, IDbTransaction dbTransaction
, String repositoryId, Boolean update)
   в Devolutions.RemoteDesktopManager.Business.DataSources.DatabaseConnectionDataSource.c0cc7f9d508f1ec50318abae3c37f1fc0(Connection cbdc2310dae04de179a24
c6e62a14e6e8, IDbTransaction c5a0ca8eaa594113c2f0b3cfe13dedff9, Nullable`1 c6c7922f70bc4ad6a683a9f6baa3f4b7d, Boolean c6d1e4c3cd1ebd972b34fc4a6a144a4e1)
   в Devolutions.RemoteDesktopManager.Business.DataSources.DatabaseConnectionDataSource.SaveConnections(IEnumerable`1 connections, IDbTransaction dbTransa
ction, ISecurityProvider provider, Nullable`1 repositoryID)
   в Devolutions.RemoteDesktopManager.Business.DataSources.DatabaseConnectionDataSource.SaveConnection(Connection connection)
Devolutions.RemoteDesktopManager.Business.Exceptions.RootException: Duplicate root creation detected!
   в Devolutions.RemoteDesktopManager.Business.DataSources.DatabaseConnectionDataSource.DetectDuplicateRoots(Connection root, IDbTransaction dbTransaction
, String repositoryId, Boolean update)
   в Devolutions.RemoteDesktopManager.Business.DataSources.DatabaseConnectionDataSource.c0cc7f9d508f1ec50318abae3c37f1fc0(Connection cbdc2310dae04de179a24
c6e62a14e6e8, IDbTransaction c5a0ca8eaa594113c2f0b3cfe13dedff9, Nullable`1 c6c7922f70bc4ad6a683a9f6baa3f4b7d, Boolean c6d1e4c3cd1ebd972b34fc4a6a144a4e1)
   в Devolutions.RemoteDesktopManager.Business.DataSources.DatabaseConnectionDataSource.SaveConnections(IEnumerable`1 connections, IDbTransaction dbTransa
ction, ISecurityProvider provider, Nullable`1 repositoryID)
   в Devolutions.RemoteDesktopManager.Business.DataSources.DatabaseConnectionDataSource.SaveConnection(Connection connection)
Devolutions.RemoteDesktopManager.Business.Exceptions.RootException: Duplicate root creation detected!
   в Devolutions.RemoteDesktopManager.Business.DataSources.DatabaseConnectionDataSource.DetectDuplicateRoots(Connection root, IDbTransaction dbTransaction
, String repositoryId, Boolean update)
   в Devolutions.RemoteDesktopManager.Business.DataSources.DatabaseConnectionDataSource.c0cc7f9d508f1ec50318abae3c37f1fc0(Connection cbdc2310dae04de179a24
c6e62a14e6e8, IDbTransaction c5a0ca8eaa594113c2f0b3cfe13dedff9, Nullable`1 c6c7922f70bc4ad6a683a9f6baa3f4b7d, Boolean c6d1e4c3cd1ebd972b34fc4a6a144a4e1)
   в Devolutions.RemoteDesktopManager.Business.DataSources.DatabaseConnectionDataSource.SaveConnections(IEnumerable`1 connections, IDbTransaction dbTransa
ction, ISecurityProvider provider, Nullable`1 repositoryID)
   в Devolutions.RemoteDesktopManager.Business.DataSources.DatabaseConnectionDataSource.SaveConnection(Connection connection)
Devolutions.RemoteDesktopManager.Business.Exceptions.RootException: Duplicate root creation detected!
   в Devolutions.RemoteDesktopManager.Business.DataSources.DatabaseConnectionDataSource.DetectDuplicateRoots(Connection root, IDbTransaction dbTransaction
, String repositoryId, Boolean update)
   в Devolutions.RemoteDesktopManager.Business.DataSources.DatabaseConnectionDataSource.c0cc7f9d508f1ec50318abae3c37f1fc0(Connection cbdc2310dae04de179a24
c6e62a14e6e8, IDbTransaction c5a0ca8eaa594113c2f0b3cfe13dedff9, Nullable`1 c6c7922f70bc4ad6a683a9f6baa3f4b7d, Boolean c6d1e4c3cd1ebd972b34fc4a6a144a4e1)
   в Devolutions.RemoteDesktopManager.Business.DataSources.DatabaseConnectionDataSource.SaveConnections(IEnumerable`1 connections, IDbTransaction dbTransa
ction, ISecurityProvider provider, Nullable`1 repositoryID)
   в Devolutions.RemoteDesktopManager.Business.DataSources.DatabaseConnectionDataSource.SaveConnection(Connection connection)
Devolutions.RemoteDesktopManager.Business.Exceptions.RootException: Duplicate root creation detected!
   в Devolutions.RemoteDesktopManager.Business.DataSources.DatabaseConnectionDataSource.DetectDuplicateRoots(Connection root, IDbTransaction dbTransaction
, String repositoryId, Boolean update)
   в Devolutions.RemoteDesktopManager.Business.DataSources.DatabaseConnectionDataSource.c0cc7f9d508f1ec50318abae3c37f1fc0(Connection cbdc2310dae04de179a24
c6e62a14e6e8, IDbTransaction c5a0ca8eaa594113c2f0b3cfe13dedff9, Nullable`1 c6c7922f70bc4ad6a683a9f6baa3f4b7d, Boolean c6d1e4c3cd1ebd972b34fc4a6a144a4e1)
   в Devolutions.RemoteDesktopManager.Business.DataSources.DatabaseConnectionDataSource.SaveConnections(IEnumerable`1 connections, IDbTransaction dbTransa
ction, ISecurityProvider provider, Nullable`1 repositoryID)
   в Devolutions.RemoteDesktopManager.Business.DataSources.DatabaseConnectionDataSource.SaveConnection(Connection connection)
Devolutions.RemoteDesktopManager.Business.Exceptions.RootException: Duplicate root creation detected!
   в Devolutions.RemoteDesktopManager.Business.DataSources.DatabaseConnectionDataSource.DetectDuplicateRoots(Connection root, IDbTransaction dbTransaction
, String repositoryId, Boolean update)
   в Devolutions.RemoteDesktopManager.Business.DataSources.DatabaseConnectionDataSource.c0cc7f9d508f1ec50318abae3c37f1fc0(Connection cbdc2310dae04de179a24
c6e62a14e6e8, IDbTransaction c5a0ca8eaa594113c2f0b3cfe13dedff9, Nullable`1 c6c7922f70bc4ad6a683a9f6baa3f4b7d, Boolean c6d1e4c3cd1ebd972b34fc4a6a144a4e1)
   в Devolutions.RemoteDesktopManager.Business.DataSources.DatabaseConnectionDataSource.SaveConnections(IEnumerable`1 connections, IDbTransaction dbTransa
ction, ISecurityProvider provider, Nullable`1 repositoryID)
   в Devolutions.RemoteDesktopManager.Business.DataSources.DatabaseConnectionDataSource.SaveConnection(Connection connection)
Devolutions.RemoteDesktopManager.Business.Exceptions.RootException: Duplicate root creation detected!
   в Devolutions.RemoteDesktopManager.Business.DataSources.DatabaseConnectionDataSource.DetectDuplicateRoots(Connection root, IDbTransaction dbTransaction
, String repositoryId, Boolean update)
   в Devolutions.RemoteDesktopManager.Business.DataSources.DatabaseConnectionDataSource.c0cc7f9d508f1ec50318abae3c37f1fc0(Connection cbdc2310dae04de179a24
c6e62a14e6e8, IDbTransaction c5a0ca8eaa594113c2f0b3cfe13dedff9, Nullable`1 c6c7922f70bc4ad6a683a9f6baa3f4b7d, Boolean c6d1e4c3cd1ebd972b34fc4a6a144a4e1)
   в Devolutions.RemoteDesktopManager.Business.DataSources.DatabaseConnectionDataSource.SaveConnections(IEnumerable`1 connections, IDbTransaction dbTransa
ction, ISecurityProvider provider, Nullable`1 repositoryID)
   в Devolutions.RemoteDesktopManager.Business.DataSources.DatabaseConnectionDataSource.SaveConnection(Connection connection)

Name                                               Group                                              ID                        
----                                               -----                                              --                        
ScriptImported                                     ScriptImported                                     e110d6b5-8b3d-42a0-bd34-390f20a71fd6                            


The user I run this from is Administrator on both windows systems and Administrator in RDM itself and has 'sysadmin' role on MSSQL server.

Any ideas what am I doing wrong? And where is that 'Duplicate root creation detected!' error in stacktrace is coming from and how to fix it?
As I've mentioned previously, user is admin everywhere (I know of) related. I've tried to go in GUI to Administration > Users > select said user and press "Fix SQL Login" - doesn't help.
Tried under different user (domain admin) - same result. So that shouldn't be permission issue, especially since it works after messing around in GUI app.

All Comments (3)

avatar

Hello,

In RDM, could you please refresh the local cache file with CTRL+F5 and in PowerShell, run the Update-RDMUI cmdlet to see if this will solve the Duplicate root issue?

I cannot reproduce this behaviour in my environment with the same RDM version and SQL data source. If I edit a folder and then try to run the same cmdlet to get the information in PowerShell, it behaves normally.

Best regards,

Érica Poirier

avatar

Hello, Erica. Thank you for quick reply.

Running Update-RDMUI right after setting data source does indeed help. In my previous tests - I haven't used Update-RDMUI at all.

Now looking at your suggestion, I've also tried to run Get-RDMCurrentDataSource right after module import and it seems like data source I've tried to set as current by running same code every time was the one that was already set. So my guess would be that due to caching - powershell module tried to "talk" to the same database/datasource twice(?) or in two different ways(?) hence duplicate root error? Not sure on that one.
But if that is the case - I think its worth to force Update-RDMUI, probably in finaly { } block of Set-RDMCurrentDataSource function in your module, maybe only if current data source is already the one user tries to set it to. That is to prevent that problem happening.

As of now, I've added that code to the beginning of my script and upon first glance it seems to work now.

Import-Module "${env:ProgramFiles(x86)}\Devolutions\Remote Desktop Manager\RemoteDesktopManager.PowerShellModule.psd1"

if ($(Get-RDMCurrentDataSource).Name -ne $rdm_datasource_name)
{
    if ($rdm_datasource_name -in $((Get-RDMDataSource).name)) # datasource present but not currently selected
    {
        $ds = Get-RDMDataSource -Name $rdm_datasource_name
        Set-RDMCurrentDataSource $ds[0]
        Update-RDMUI
    }
    else # rdm datasource doesn't exist yet
    {
        # connect to correct datasource
        New-RDMDataSource -Database $rdm_db_name -Name $rdm_datasource_name -Server $rdm_db_server -IntegratedSecurity -SQLServer -SetDatasource
        
        # remove all the other datasources
        Get-RDMDataSource | Where-Object -FilterScript {$_.Name -ne $rdm_datasource_name} | Remove-RDMDataSource

        # rebuild cache
        Update-RDMUI
    }
}
else
{
    # rebuild cache
    Update-RDMUI
}


avatar

Hello,

Thank you for your feedback and glad that it's now working.

The duplicate root error is related to the fact that RDM (application or PowerShell module) is unable to read the root record on the local cache file and tries to create it. That triggers the duplicate root error because the root record exist in the database. The Update-RDMUI cmdlet will refresh the local cache file and you will be sure that this file is not ocrrupted.

Best regards,

Érica Poirier