Overview
When setting up external object connections to an SQL server, the "Test Connection" button on the connection dialog itself works, but clicking the "Refresh Columns" button fails, and the objects are not imported to M-Files.This happens when you have selected "Use Windows NT Integrated Security" as the authentication mechanism for the SQL server connection. The current user (you), however, has permissions to use that database in the SQL Server.
The error in the exception message is something like
Connection with the external database failed.
or
Cannot open the "database name here" database requested by the connection. The connection failed. (ERROR: 4060, SQLSTATE: 42000)
Below you will find:
- A screenshot illustrating the issue.
- A section describing the cause for this behavior.
- Several solutions to choose from.
Figure 1: Set up an external Object Type connection to an SQL server with current Windows User which might fail
Cause
The "Test Connection" button in the M-Files Admin uses the current Windows User that you used to log in to the computer.The M-Files Server, however, is a service that by default uses the local system user identity on the computer. It does not use the current Windows user. However, the service can be configured to log on using some user account or a service user.
The M-Files Admin is a separate process which does not run within the M-Files Server process and typically these two are run under different user contexts. As such the resources - such as network shares - visible to the M-Files Admin may not be the same as those visible to the server.
Solution
When setting up authentication to external sources (and performing any other operations that require access to some resources such as disks) you must remember in the previously discussed user context issue.For example, for an SQL connection for External Objects, you have three options:
- Recommended: Use a named user through the "Use a specific user name and password" option, and, on the SQL server, create a dedicated account to the sql server that will be used for this connection.
This allows for the following benefits:- You can manage those credentials in the SQL server.
- The password expiration and policy are easier to control than with a federated authentication provider.
- You do not need to set up an entire user in a complicated system like AD/ADFS since it is not a real human user that needs access to other resources.
- The account has no other access than to the SQL server
- Use a dedicated account with Windows Login that you already have, through the "Use a specific user name and password" option.
- This requires that you have access to its credentials and if they change you must also update the M-Files settings.
- You should not use your own personal user for this.
- Not recommended: Provide access to the local system account from the machine where M-Files Server runs to the SQL server. This would allow you to keep using the "Use Windows NT Integrated security" option.
- Note that this might not always be possible, and it might be a bad practice from security and isolation point of view.
