# Get SRConnection for Project's Default Database

**URL:** <https://forum.inductiveautomation.com/t/get-srconnection-for-projects-default-database/4254>\
**Category:** Module Development\
**Created:** [April 5, 2012, 5:20pm UTC](https://forum.inductiveautomation.com/t/get-srconnection-for-projects-default-database/4254 "2012-04-05T17:20:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bryan\_cook](https://avatars.discourse-cdn.com/v4/letter/b/a8b319/32.png) [@bryan\_cook](https://forum.inductiveautomation.com/u/bryan_cook)\
**Post date:** [April 5, 2012, 5:20pm UTC](https://forum.inductiveautomation.com/t/get-srconnection-for-projects-default-database/4254/1 "2012-04-05T17:20:34Z")

</div>

How can I go about getting an SRConnection object for the project’s default database? We’ve got a Gateway module and we’re able to get them through GatewayContext.getDatasourceManager().getConnection(); however, ClientContext doesn’t have a getDatasourceManager() method, just getDefaultDatasourceName(). I’ve been cruising through the API javadocs but can’t seem to find what I’m looking for.

Thanks!

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [April 5, 2012, 5:56pm UTC](https://forum.inductiveautomation.com/t/get-srconnection-for-projects-default-database/4254/2 "2012-04-05T17:56:42Z")

</div>

You don’t get an SRConnection from the client.

All database stuff goes through the GatewayInterface if you’re in the client/designer. You get the GatewayInterface from GatewayConnectionManager.getInstance().getGatewayInterface()

From here you can run queries. If you leave the database connection name blank, it run’s against the project’s default.

---

<div class="post-metadata">

**Author:** ![bryan\_cook](https://avatars.discourse-cdn.com/v4/letter/b/a8b319/32.png) [@bryan\_cook](https://forum.inductiveautomation.com/u/bryan_cook)\
**Post date:** [April 5, 2012, 6:43pm UTC](https://forum.inductiveautomation.com/t/get-srconnection-for-projects-default-database/4254/3 "2012-04-05T18:43:48Z")

</div>

We’re using a [third-party library](http://www.jooq.org/) for database interactions, thinking about moving towards a full-blown ORM in the future. When querying, we’ve got to provide our [Factory](http://www.jooq.org/javadoc/latest/org/jooq/impl/Factory.html) object a java.sql.Connection …

`
SRConnection conn = getConnection(); // Uses GatewayContext.getDatasourceManager().getConnection()
DataFactory db = new DataFactory(conn);
Result<VegetableRecord> results = db.selectFrom(Tables.VEGETABLE).where(Tables.VEGETABLE.COLOR.equal("Red")).fetch();
`So, that’s the reasoning behind my request for an SRConnection object. We’ve got all the querying logic encapsulated in repositories; however, without a Connection object, we can’t make use of these repositories at the Client/Designer level.
