N8n Connect to SQL Server Database
To make n8n connect to sql server database systems, you add a database login and credentials. You then link those stored credentials to a workflow node or an AI agent tool. This setup lets your workflows and AI agents read or write data on demand. Still, static keys and broad database roles can expose live data during an active session. How to make n8n connect to sql server database workflows In n8n, workflows run queries by using saved database credentials in a dedicated node. When you buil
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
To make n8n connect to sql server database systems, you add a database login and credentials. You then link those stored credentials to a workflow node or an AI agent tool.
This setup lets your workflows and AI agents read or write data on demand. Still, static keys and broad database roles can expose live data during an active session.
How to make n8n connect to sql server database workflows
In n8n, workflows run queries by using saved database credentials in a dedicated node. When you build an AI workflow, the n8n AI Agent node pairs a chat model with tools. The agent decides which tool sub-node to call so it can finish a task. You must attach at least one tool sub-node to an AI Agent node.
From n8n 1.82.0, the old agent type setting is deprecated for new builds. Every AI Agent node now works as a Tools Agent by default. Node version 1, which had that setting, is removed in n8n 3.0. The older SQL Agent only listed MySQL, SQLite, and Postgres as built-in data sources.
To reach SQL Server from an agent, teams often use a Call n8n Workflow Tool. That tool triggers a separate child workflow that holds the SQL Server node. Teams can also connect an HTTP Request Tool, a Custom Code Tool, or MCP servers. Each option passes the query from the agent to the database and returns results.
How SQL Server logins and database roles work
On the database side, you must set up a login and a database user. A database user is the identity a login uses when it joins a database. SQL Server supports 13 different types of database users for various access needs.
If an app needs many databases on one instance, a login in master is common. If it only needs one or a few databases, a contained database user works well. A contained user has its own password and does not tie to a master login. An admin must first enable contained databases on the server and the target database.
Database Connection Strings Security + Kubernetes API Server Access: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
After you create the user, you assign it to fixed database roles. Every role, including the public role, has basic permission to reach the database. Members of the db_datareader role can read all data from all user tables and views. Members of db_datawriter can add, delete, or change data in all user tables.
You can also block actions with deny roles when you need stricter boundaries. The db_denydatareader role blocks reading any data or metadata from user tables and views. The db_denydatawriter role stops a user from adding, changing, or deleting any table data. In contrast, the db_owner role can run all maintenance tasks and even drop the database.
Security tradeoffs of static credentials and fixed roles
Fixed database roles give you a fast way to set up basic access rules. Still, SQL Server does not let you change the permissions assigned to fixed roles. If you put an n8n user in db_datareader, it reads every user table.
That broad read scope creates risk when workflows or AI agents run open queries. A prompt mistake or bad workflow step can pull sensitive rows from any table. Raw results may hold emails, phone numbers, card numbers, or national IDs. Static credentials stored in an automation app also stay valid until someone rotates them.
To reduce risk, teams put a policy layer between the workflow tool and the database. This layer checks each query before it runs and logs the full activity trail. It can also apply data masking to rewrite matched fields like emails or card numbers in results. Adding approval steps for write queries further protects production tables from bad updates.
Govern SQL Server queries and responses in flight
Table grants decide which SQL Server objects a caller may touch. They do not check query intent or rewrite sensitive values in results across every client and agent. By design, hoop.dev sits inline in the TDS wire protocol next to SQL Server as a sidecar for your SQL Server. On every production batch from an engineer or AI agent, hoop.dev decides to pass, mask, block, or hold it for approval.
With hoop.dev guardrails and hoop.dev data masking, banned statements are refused or held for review, matched sensitive fields in supported result columns are masked in memory, and each decision is logged. Check out the code on GitHub.
Frequently asked questions
Can the n8n AI Agent node query SQL Server directly?
The deprecated SQL Agent only supported MySQL, SQLite, and Postgres directly. In current versions, you use a Tools Agent paired with a Call n8n Workflow Tool or MCP server to run SQL Server queries.
Should I use a master login or a contained user for n8n?
Use a contained database user if n8n only needs one or a few databases. Use a SQL user with a master login if n8n must reach many databases on the same server instance.
Does the db_datareader role hide sensitive columns from n8n?
No, members of db_datareader can read all data from all user tables and views. To hide specific fields like phone numbers or card numbers, you need a query masking layer or custom permissions.
Related guides
In this post