# Connecting to MSSQL server with a linked server

**URL:** <https://forum.inductiveautomation.com/t/connecting-to-mssql-server-with-a-linked-server/96422>\
**Category:** General Discussion\
**Tags:** database\
**Created:** [September 25, 2024, 2:11pm UTC](https://forum.inductiveautomation.com/t/connecting-to-mssql-server-with-a-linked-server/96422 "2024-09-25T14:11:02Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Victor\_Anderson](https://avatars.discourse-cdn.com/v4/letter/v/b19c9b/32.png) [@Victor\_Anderson](https://forum.inductiveautomation.com/u/Victor_Anderson)\
**Post date:** [September 25, 2024, 2:11pm UTC](https://forum.inductiveautomation.com/t/connecting-to-mssql-server-with-a-linked-server/96422/1 "2024-09-25T14:11:02Z")

</div>

Hello, I'm trying to connect to a MSSQL server which is connected to our ERP system.  
Since our ERP uses ODBC for connection I've set up a linked server in SSMS which works fine, although when I'm trying to run a query Ignition returns error -155.

Error from Designer:

> Error running query: SELECT \* FROM OPENQUERY([Server], 'SELECT \* FROM [schema].[table]') WHERE status = 3 Unknown SQL type: -155

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 25, 2024, 2:24pm UTC](https://forum.inductiveautomation.com/t/connecting-to-mssql-server-with-a-linked-server/96422/2 "2024-09-25T14:24:04Z")

</div>

There is something in that linked server that is using a column type that your MS JDBC driver doesn't support. Are you using the latest JDBC driver for your java/sql server combination?

---

<div class="post-metadata">

**Author:** ![Victor\_Anderson](https://avatars.discourse-cdn.com/v4/letter/v/b19c9b/32.png) [@Victor\_Anderson](https://forum.inductiveautomation.com/u/Victor_Anderson)\
**Post date:** [September 26, 2024, 5:06am UTC](https://forum.inductiveautomation.com/t/connecting-to-mssql-server-with-a-linked-server/96422/3 "2024-09-26T05:06:40Z")

</div>

I'm running Ignition 8.1.4, with the JDBC driver 9.4.0. Would an upgrade possibly resolve the issue?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 26, 2024, 12:07pm UTC](https://forum.inductiveautomation.com/t/connecting-to-mssql-server-with-a-linked-server/96422/4 "2024-09-26T12:07:13Z")

</div>

Maybe, but be aware that upgrading Ignition doesn't upgrade the JDBC driver. That would be a separate operation (that you can do now).

---

<div class="post-metadata">

**Author:** ![Victor\_Anderson](https://avatars.discourse-cdn.com/v4/letter/v/b19c9b/32.png) [@Victor\_Anderson](https://forum.inductiveautomation.com/u/Victor_Anderson)\
**Post date:** [September 26, 2024, 12:22pm UTC](https://forum.inductiveautomation.com/t/connecting-to-mssql-server-with-a-linked-server/96422/5 "2024-09-26T12:22:23Z")

</div>

I tried updating the driver to the latest file from MS (12.8.1.0 java 11), but that resulted in an connection error to the database, so I had to go back to the original. Is there a way to set up a new database connection directly to my linked server?

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [September 26, 2024, 12:28pm UTC](https://forum.inductiveautomation.com/t/connecting-to-mssql-server-with-a-linked-server/96422/6 "2024-09-26T12:28:03Z")

</div>

> [@Can query SQL tables, but cannot query SQL views, GatewayException: Unknown SQL type: -156](https://forum.inductiveautomation.com/t/can-query-sql-tables-but-cannot-query-sql-views-gatewayexception-unknown-sql-type-156/43877):
>
> GatewayException: Unknown SQL type: -156 caused by SQLException: Unknown SQL type: -156 Ignition v8.0.16 (b2020082513) Java: Azul Systems, Inc. 11.0.7 Other information:SQL version: 13.0.4001.0

Instead of doing a `SELECT *` list your columns and CAST the problematic column.

---

<div class="post-metadata">

**Author:** ![Victor\_Anderson](https://avatars.discourse-cdn.com/v4/letter/v/b19c9b/32.png) [@Victor\_Anderson](https://forum.inductiveautomation.com/u/Victor_Anderson)\
**Post date:** [September 26, 2024, 1:12pm UTC](https://forum.inductiveautomation.com/t/connecting-to-mssql-server-with-a-linked-server/96422/7 "2024-09-26T13:12:14Z")

</div>

THIS WORKS!!! Thank you very much 😄

---

<div class="post-metadata">

**Author:** ![Steve\_Laubach](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/steve_laubach/32/60900_2.png) [@Steve\_Laubach](https://forum.inductiveautomation.com/u/Steve_Laubach)\
**Post date:** [September 26, 2024, 3:18pm UTC](https://forum.inductiveautomation.com/t/connecting-to-mssql-server-with-a-linked-server/96422/8 "2024-09-26T15:18:02Z")

</div>

If you're querying data from linked servers in MSSQL I would recommend putting your queries in stored procedures so future JDBC driver changes can't impact functionality.
