Forum Discussion
Establish an Oracle Database Connection hosted on Azure VM via AI Foundry Agent
I have came across a requirement to create a AI Foundry agent that will accept requests from user like below:
a. "I want to connect to abcprd database hosted on subscription sub1, and resource group rg1 and check the AWR report from xAM-yPM on a specific date (eg 21-Oct-2025)
b. Check locking session/RMAN backup failures/active sessions from the database abcprd hosted on subscription sub1, and resource group rg1.
The agent should be able to fetch the relevant query from knowledge base . connect to the database and run the report for the duration mentioned. It should then fetch the report and pass it to the LLM (GPT 4.1 in our case) for investigations.
I am looking for approach to connect to the oracle database based on user's request and execute the query obtained from knowledge base.
2 Replies
- Imran ShakeelCopper Contributor
Recommended approaches
AI Foundry (Intent + Orchestration)
- Parse user Intent (AWR Report, locking sesson RMAN faliure , active sessions)
- Extract params (DB Name, date, time window, subscriont, RG)
- Select the correct query template id (not raw sql)
Second - (Knowledge Base (Query Template)
- AWR_REPORT
- LOCKING_SESSION
- RMAN_FALIURES
- ACTIVE_SESSION
Third - (Tool layer - Oracle Execution)
Accepts: OperationId (get_awrt_report)
parameters: (Date, time range, db name)
executes only white listed SQL Templates
Oracle connectivity can also be a better approach; you can use Python-oracledb, a read-only DBA user, etc.
Example: Query--> DBA_HIST_* views /generated report via standard AWR script
time window (xAM-yPM on a date) map to snapshot id
The following could be your workflow (production safe approach)
User →
AI Foundry Agent →
Select Query Template (KB) →
Call Oracle Ops API (Tool) →
Execute on Oracle →
Return results →
GPT‑4.1 analysis
- AnjaliSadhukhan
Microsoft
do try if helps-
- Build a Custom Function Tool (API Layer)
- Deploy an Azure Function or containerized API on the same VNet as your Oracle VM.
- Use python-oracledb or cx_Oracle to connect to the database.
- Store Oracle credentials in Azure Key Vault (access via Managed Identity — never hardcode).
- Knowledge Base for SQL Templates
- Store your query templates (AWR, V$SESSION, V$LOCKED_OBJECT, RMAN status, etc.) in Azure AI Search or Blob Storage.
- Agent retrieves the right template based on user intent, then parameterizes it with date/time/DB name.
- Agent Flow
- User prompt → Agent extracts intent + parameters → Calls function tool → Tool connects to Oracle DB, runs query → Returns results → Agent analyzes/summarizes via GPT-4.1.
- Key Security & Design Points
- Use VNet integration / Private Endpoints — no public DB exposure.
- Oracle user should be read-only (SELECT grants only).
- Use parameterized queries to prevent SQL injection.
- Use connection pooling to avoid per-request overhead.
- For large AWR reports, extract key sections (Top SQL, Wait Events, Load Profile) before passing to the LLM to stay within token limits.