# How to fetch data from MSSQL

**URL:** <https://forum.inductiveautomation.com/t/how-to-fetch-data-from-mssql/83665>\
**Category:** Ignition\
**Tags:** perspective, ignition81\
**Created:** [January 2, 2024, 4:48am UTC](https://forum.inductiveautomation.com/t/how-to-fetch-data-from-mssql/83665 "2024-01-02T04:48:23Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sachin\_Jagtap](https://avatars.discourse-cdn.com/v4/letter/s/b487fb/32.png) [@Sachin\_Jagtap](https://forum.inductiveautomation.com/u/Sachin_Jagtap)\
**Post date:** [January 2, 2024, 4:48am UTC](https://forum.inductiveautomation.com/t/how-to-fetch-data-from-mssql/83665/1 "2024-01-02T04:48:23Z")

</div>

```with

```

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [January 2, 2024, 6:43am UTC](https://forum.inductiveautomation.com/t/how-to-fetch-data-from-mssql/83665/2 "2024-01-02T06:43:57Z")

</div>

Could you be a little more specific?  
• Is your database connection good?  
• Is your query failing for some reason?  
• Is there an exception report that you need help interpreting?

---

<div class="post-metadata">

**Author:** ![Sachin\_Jagtap](https://avatars.discourse-cdn.com/v4/letter/s/b487fb/32.png) [@Sachin\_Jagtap](https://forum.inductiveautomation.com/u/Sachin_Jagtap)\
**Post date:** [January 2, 2024, 10:46am UTC](https://forum.inductiveautomation.com/t/how-to-fetch-data-from-mssql/83665/3 "2024-01-02T10:46:42Z")

</div>

i write this query to fetch data " SELECT Photo from ImageTable where id= :id ; "

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [January 2, 2024, 11:16am UTC](https://forum.inductiveautomation.com/t/how-to-fetch-data-from-mssql/83665/4 "2024-01-02T11:16:07Z")

</div>

> [@justinedwards.jle](#):
>
> Could you be a ~~little~~ lot more specific?

Fixed that for you.

@Sachin_Jagtap How are you trying to use this query? While the syntax suggests a named query, you have not provided any context.

More information usually yields better answers.

---

<div class="post-metadata">

**Author:** ![Sachin\_Jagtap](https://avatars.discourse-cdn.com/v4/letter/s/b487fb/32.png) [@Sachin\_Jagtap](https://forum.inductiveautomation.com/u/Sachin_Jagtap)\
**Post date:** [January 2, 2024, 11:31am UTC](https://forum.inductiveautomation.com/t/how-to-fetch-data-from-mssql/83665/5 "2024-01-02T11:31:57Z")

</div>

i bind the query to image component by passing parameter

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [January 2, 2024, 11:33am UTC](https://forum.inductiveautomation.com/t/how-to-fetch-data-from-mssql/83665/6 "2024-01-02T11:33:54Z")

</div>

It's not working? What errors do you have? On the gateway web page, is the database connection faulted?

**Edit: Another troubleshooting check:**  
Is the database specified in the binding? _[It's a dropdown at the bottom of the binding editor]_

---

<div class="post-metadata">

**Author:** ![Sachin\_Jagtap](https://avatars.discourse-cdn.com/v4/letter/s/b487fb/32.png) [@Sachin\_Jagtap](https://forum.inductiveautomation.com/u/Sachin_Jagtap)\
**Post date:** [January 2, 2024, 11:46am UTC](https://forum.inductiveautomation.com/t/how-to-fetch-data-from-mssql/83665/7 "2024-01-02T11:46:03Z")

</div>

data is fetched but in the binary form

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [January 2, 2024, 11:57am UTC](https://forum.inductiveautomation.com/t/how-to-fetch-data-from-mssql/83665/8 "2024-01-02T11:57:05Z")

</div>

Sachin, you are making it very difficult to help you. Your first post is empty. You did not say that you are trying to retrieve image files. In now seems that you are connected to the database but you are getting images back in binary form and you are expecting something else.

Please write a post that explains

1. Your setup.
2. What you want.
3. How you are trying to do it.
4. What result and problem you have at the moment.

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [January 2, 2024, 11:58am UTC](https://forum.inductiveautomation.com/t/how-to-fetch-data-from-mssql/83665/9 "2024-01-02T11:58:18Z")

</div>

~~f it's what I think it is, it makes sense. I've seen this in the forum before. Give me a sec, I'll see if I can find it.~~

**Edit:** I found the post I was looking for, and it's not related to this.

If I'm reading this correctly, he's querying a blob of an image, and he needs help converting the bytes back into an image file to display it somehow.

---

<div class="post-metadata">

**Author:** ![Sachin\_Jagtap](https://avatars.discourse-cdn.com/v4/letter/s/b487fb/32.png) [@Sachin\_Jagtap](https://forum.inductiveautomation.com/u/Sachin_Jagtap)\
**Post date:** [January 2, 2024, 12:16pm UTC](https://forum.inductiveautomation.com/t/how-to-fetch-data-from-mssql/83665/10 "2024-01-02T12:16:30Z")

</div>

I am trying to fetch data from MSSQL database ,connection is valid  
i write named query to fetch data which gives me output also but when i bind this query to image component image is not visible

---

<div class="post-metadata">

**Author:** ![Sachin\_Jagtap](https://avatars.discourse-cdn.com/v4/letter/s/b487fb/32.png) [@Sachin\_Jagtap](https://forum.inductiveautomation.com/u/Sachin_Jagtap)\
**Post date:** [January 2, 2024, 12:17pm UTC](https://forum.inductiveautomation.com/t/how-to-fetch-data-from-mssql/83665/11 "2024-01-02T12:17:31Z")

</div>

it require datatype conversion ?

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [January 2, 2024, 12:22pm UTC](https://forum.inductiveautomation.com/t/how-to-fetch-data-from-mssql/83665/12 "2024-01-02T12:22:43Z")

</div>

Look at these posts about converting a blob to an image in Perspective:  
[https://forum.inductiveautomation.com/search?q=Blob%20image%20tags%3Aperspective](https://forum.inductiveautomation.com/search?q=Blob%20image%20tags%3Aperspective)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [January 2, 2024, 12:26pm UTC](https://forum.inductiveautomation.com/t/how-to-fetch-data-from-mssql/83665/13 "2024-01-02T12:26:59Z")

</div>

And this one.

> [@Retrieve and Display a BLOB in Perspective](https://forum.inductiveautomation.com/t/retrieve-and-display-a-blob-in-perspective/27114/5):
>
> If you don't have webdev you can do something like this.

---

<div class="post-metadata">

**Author:** ![Sachin\_Jagtap](https://avatars.discourse-cdn.com/v4/letter/s/b487fb/32.png) [@Sachin\_Jagtap](https://forum.inductiveautomation.com/u/Sachin_Jagtap)\
**Post date:** [January 3, 2024, 4:22am UTC](https://forum.inductiveautomation.com/t/how-to-fetch-data-from-mssql/83665/14 "2024-01-03T04:22:07Z")

</div>

Thank You So Much Now It's Working.
