# Execute query using a database connection from a different server

**URL:** <https://forum.inductiveautomation.com/t/execute-query-using-a-database-connection-from-a-different-server/72405>\
**Category:** Ignition\
**Tags:** perspective, ignition81\
**Created:** [April 13, 2023, 1:55pm UTC](https://forum.inductiveautomation.com/t/execute-query-using-a-database-connection-from-a-different-server/72405 "2023-04-13T13:55:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dwb](https://avatars.discourse-cdn.com/v4/letter/d/9dc877/32.png) [@dwb](https://forum.inductiveautomation.com/u/dwb)\
**Post date:** [April 13, 2023, 1:55pm UTC](https://forum.inductiveautomation.com/t/execute-query-using-a-database-connection-from-a-different-server/72405/1 "2023-04-13T13:55:35Z")

</div>

Hi,

I am using Igntion 8.1.25 making a project in Perspective.  
I set up the Database connection in my Named Queries as "Parameter", so that I can change it dinamically on my screen. I'm being able to do it, I can change to a different database I have in my server.  
But now I'd like to change to a database located in a different server.  
How can I do it?  
Thanks.

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [April 13, 2023, 2:00pm UTC](https://forum.inductiveautomation.com/t/execute-query-using-a-database-connection-from-a-different-server/72405/2 "2023-04-13T14:00:56Z")

</div>

Make a separate db connection in the gateway and point it to the server's hostname and port.

[Database Connections - Ignition User Manual 8.1 - Ignition Documentation (inductiveautomation.com)](https://docs.inductiveautomation.com/display/DOC81/Database+Connections)

---

<div class="post-metadata">

**Author:** ![dwb](https://avatars.discourse-cdn.com/v4/letter/d/9dc877/32.png) [@dwb](https://forum.inductiveautomation.com/u/dwb)\
**Post date:** [April 13, 2023, 2:11pm UTC](https://forum.inductiveautomation.com/t/execute-query-using-a-database-connection-from-a-different-server/72405/3 "2023-04-13T14:11:55Z")

</div>

Thank you.  
So it means I'll be able to see only the dB connections I have in my server. I can't via script connect directly to a different server.  
Is that?

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [April 13, 2023, 2:16pm UTC](https://forum.inductiveautomation.com/t/execute-query-using-a-database-connection-from-a-different-server/72405/4 "2023-04-13T14:16:31Z")

</div>

You can add a connection to a database with scripting, but it usually makes more sense to make db connections in the gateway to every db source you want to access.

[system.db.addDatasource - Ignition User Manual 8.1 - Ignition Documentation (inductiveautomation.com)](https://docs.inductiveautomation.com/display/DOC81/system.db.addDatasource)
