Describe the problem/error/question
I want to dynamically change the database name field inside a credential, based on a value selected in a previous node , since multiple databases exist on the same server and I need to switch between them at runtime.
When I try to use an expression in the credential’s database name field (referencing data from a previous node),
I get this error:ERROR: No path back to node
Is there any supported workaround to switch database names dynamically per execution?
Edit: I’ll try to be clearer.
It’s my MSSQL credential setup. Through a dropdown, I am selecting the DB name, and then some query nodes are executed further (in that DB).
What I am trying to do: since there is an option to take the DB name through an expression, I tried:
The second one didn’t throw an error — it got saved and executed, but returned no output.
So I’m not sure what I’m missing in passing the selected DB name dynamically.
Hi @Adarsh_Kumar Welcome!
for persistent usage i would recommend using the HTTP node with custom auth, as you are dynamically switching credentials which might not be fully supported so you gotta test things, first go with the HTTP node, and also try some expression and see the executions that does it give a error:
{{ $('NodeName').first().json.databaseName }} → Just make sure that node is connected to that node via some way.
There can be a different way also like creating a separate credentials per database but that would be too much work but it might help at certain things using a switch to route the databases between flows dynamically.
yeah this is a known limitation — credentials in n8n are resolved outside of the execution context so they can’t reference data from previous nodes, which is what causes that “no path back to node” error. expressions just don’t work there.
two workarounds:
- create a separate credential per database and use a Switch node to route to the right one based on the value from your previous node
- skip the native db node for these cases and use an HTTP Request node instead — build the connection/auth headers dynamically from your expression
option 1 is simpler if you’re switching between just a few databases, option 2 scales better if you have many