Hi, is it possible to access a Native NAV db using CFront via Powershell? We are looking at automating a data extract of a table but are having trouble connecting to the db. Demo code is posted below. The problem is that ::Instance always returns $null, so we can't access any methods underneath it.
### # Load Native Database Libraries # # Settings $DriverType = [Microsoft.Dynamics.NAV.CFront.NavisionDriverType]::Native $HideErrors = $False $NavisionPath = "C:\ProgramData\Microsoft\Microsoft Dynamics NAV\60\Database" $HostName = "Localhost" $NetType = [Microsoft.Dynamics.NAV.CFront.NavisionNetType]::NativeSecureTcp $DatabaseName = "C:\ProgramData\Microsoft\Microsoft Dynamics NAV\60\Database\database.fdb" $CacheSize = 2000 $UseCommitBack = $True $UseNTAuthentication = $True $UserID = "" $Password = "" # Open the connection [Reflection.Assembly]::LoadWithPartialName("Microsoft.Dynamics.NAV.CFront.CFrontDotNet") [Microsoft.Dynamics.NAV.CFront.CFrontDotNet]::DriverType = $DriverType [Microsoft.Dynamics.NAV.CFront.CFrontDotNet]::HideErrors = $HideErrors [Microsoft.Dynamics.NAV.CFront.CFrontDotNet]::NavisionPath = $NavisionPath "Open Connection..." [Microsoft.Dynamics.NAV.CFront.CFrontDotNet]::Instance.ConnectServerAndOpenDatabase($HostName,$NetType,$DatabaseName,$CacheSize,$UseCommitBack,$UseNTAuthentication,$UserID,$Password)
The output of the script is:
GAC Version Location
--- ------- -------- True v2.0.50727 C:\Windows\assembly\GAC_MSIL\Microsoft.Dynamics.NAV.CFront.CFrontDotNet\6.0.0.0__31bf3856ad364e35\Microsoft.Dynamics.NAV.CFront.CFrontDotNet.dll Open Connection... You cannot call a method on a null-valued expression. At ##Script Name##.ps1:24 char:1 + [Microsoft.Dynamics.NAV.CFront.CFrontDotNet]::Instance.ConnectServerAndOpenDatab ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull
Any guidance or assistance most welcome.
Thanks,
Jay :)
*This post is locked for comments