How to Configure Dify SQL Server Credentials
To set up dify sql server credentials, create a dedicated database user with read-only roles. Then, add those login details to your AI workflow tool. Most teams start by reusing an admin account to test a quick build. That fast choice creates big risks when an AI agent runs queries on its own. Broad permissions let a bad prompt change tables, drop data, or read private records. How to set up dify sql server credentials First, you need to pick the right user type in your database. A database u
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 set up dify sql server credentials, create a dedicated database user with read-only roles. Then, add those login details to your AI workflow tool. Most teams start by reusing an admin account to test a quick build. That fast choice creates big risks when an AI agent runs queries on its own. Broad permissions let a bad prompt change tables, drop data, or read private records.
How to set up dify sql server credentials
First, you need to pick the right user type in your database. A database user is the identity of a login when it connects to a database. If your AI app needs many databases on one instance, use a login in master. If the app needs just one database, you can use a contained database user. This user has a password and does not tie to a login in master. An admin must turn on contained databases on the server and database first.
Next, you must assign a strict role to this new database user. Do not give the account the owner role. The owner role can run all maintenance tasks and can even drop the database. Instead, add your new user to the fixed data reader role. Members of this role can read all data from all user tables and views. You can also add the deny data writer role for extra safety. That role makes sure the user cannot add, change, or delete any table data. Note that you cannot change the permissions built into these fixed database roles.
Once the user and roles are ready, you add the login details to Dify. Your AI workflows will then use this single account to run every SQL query.
What native roles solve and what they miss
Native database roles are great for stopping direct data changes or table drops. A read-only role stops an AI agent from deleting rows by mistake. It also blocks the app from changing how the database works.
Ephemeral Credentials + Kubernetes API Server Access: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Still, native roles only check who logs in at the start of a session. They do not inspect what individual queries do while they run in flight. Because the data reader role reads all user tables, the AI can query anything. It can still pull sensitive columns like emails, phone numbers, card numbers, or national IDs. Also, every person using the Dify app shares that one database login. When a bad query hits the server, your database logs only show that shared user. You cannot tell which team member or workflow triggered the request. Static passwords stored in your app settings also create a leak risk over time.
Managing sensitive data and shared accounts
When AI tools query live data, read-only access is only the first step. Teams also need a way to control which columns return in query results. Masking rules can rewrite matched fields like emails or card numbers in results. This keeps private data out of AI prompts without breaking the SQL query. Teams also need clear audit logs that tie each query to a real person. That way, you know who asked the AI to run a specific data check.
Check SQL Server batches and results on the wire
SQL Server logins and roles decide who connects. They do not check what each TDS batch does or mask sensitive values in returned rows. With hoop.dev, you run an open-source proxy, a sidecar for your SQL Server. It reads plain batches and parameterized queries on the TDS wire while passing Windows login through untouched.
Before a batch hits the server, hoop.dev guardrails check the statement against your rules. Disallowed actions get a native TDS error with your message. On the way back, hoop.dev data masking rewrites sensitive values in supported result columns that match your rules. Every query and decision is logged. Explore the MIT-licensed project on GitHub.
Frequently asked questions
Should I use a master login or a contained user for Dify?
Use a contained user if your Dify workflow only reads from one database. Use a login in master if the app needs to read many databases.
Can I customize the permissions inside the fixed data reader role?
No, SQL Server does not let you change permissions assigned to fixed database roles. To block specific tables, you must set up custom roles or table rules.
Why is the database owner role risky for AI workflows?
The owner role can change settings, alter tables, and drop the entire database. An AI agent with this role could wipe out data if a prompt goes wrong.
Related guides
In this post