Categories
Dynamics NAV Microsoft PowerShell SQL Server

Import-NAVEncryptionKey : Cannot establish a connection to the SQL Server/Database

If you are sure that the values inserted in the parameters are correct but you are receiving the following error message:

Import-NAVEncryptionKey : Cannot establish a connection to the SQL Server/Database.

This could be due to one of the following reasons:
* SQL Server is not started.
* The database does not exist.
* Proper permissions have not been given to the NAV Server Account.
Try again later or contact your system administrator.
At line:1 char:1
+ Import-NAVEncryptionKey
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (0:Int32) [Import-NAVEncryptionKey], NavCSideException
+ FullyQualifiedErrorId : Microsoft.Dynamics.Nav.Management.Cmdlets.ImportNavEncryptionKey

Cause:
Maybe the user you are using to run the script does not have access to the db, this is a common issue when you use ‘Database Authentication Mode = SQL Server Authentication’. To be safe use the same account you set up in the instance for the ‘Database Credentials’.

Solution:
Run Windows PowerShell ISE as Administrator and run the following script changing placeholders with the angle brackets (<>) with your values

Set-ExecutionPolicy unrestricted -Force
Import-Module 'C:\Program Files\Microsoft Dynamics NAV\<NavVersion>\Service\NavAdminTool.ps1'

$Credential = (New-Object PSCredential -ArgumentList '<LoginName>',(ConvertTo-SecureString -AsPlainText -Force '<Password>'))

Import-NAVEncryptionKey -ApplicationDatabaseCredentials $Credential -ApplicationDatabaseServer <DatabaseServer> -ApplicationDatabaseName <DatabaseName> -KeyPath '<KeyFilePath>' -ServerInstance <InstanceName> -Force

Did my solution solve your problem? Leave a reply.

Categories
Dynamics NAV Microsoft SQL Server

There are some objects locked in the database. You must unlock these objects before upgrading the database

—————————
Microsoft Dynamics NAV Development Environment
—————————
There are some objects locked in the database. You must unlock these objects before upgrading the database.
—————————
OK
—————————

Solution:
Execute the following SQL Query, remind to USE your database name (replace NAVDatabase)

USE [NAVDatabase]

UPDATE [Object] SET [Locked] = 0, [Locked By] = '' WHERE [Locked] = 1

then close the query window (otherwise the connection will still remain active).

Did my solution solve your problem? Leave a reply.