# Database Access (Python Database API Specification v2.0)

**URL:** <https://forum.inductiveautomation.com/t/database-access-python-database-api-specification-v2-0/69713>\
**Category:** Maker\
**Tags:** ignition81, database, scripting\
**Created:** [February 10, 2023, 7:49pm UTC](https://forum.inductiveautomation.com/t/database-access-python-database-api-specification-v2-0/69713 "2023-02-10T19:49:39Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alan\_Cannon](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alan_cannon/32/31171_2.png) [@Alan\_Cannon](https://forum.inductiveautomation.com/u/Alan_Cannon)\
**Post date:** [February 10, 2023, 7:49pm UTC](https://forum.inductiveautomation.com/t/database-access-python-database-api-specification-v2-0/69713/1 "2023-02-10T19:49:39Z")

</div>

Hello All,  
Start out with quite new and just completing Certification's in class now.. However, as i keep reading between (Python,Jython, Java) it seems that i can (but might not understand the relationships) connect python to odbc (pyodbc) or ado (pyadodb) in a traditional manner. i understand there are "named queries" and Sql connectors, but as i am through all of the videos and in class i see some opportunities for scripting i would just like to do my self.  
i have downloaded and installed Python, PiP, Jython and followed what i could to copy my .py files from [Python install directory\ site-packages] to [Iginition install directory\site-packages]. Opened the script console and "Import pyodbc" as my first example. Error: no module named pyodbc and the same for "import pymssql" Error: no module named pymssql. So i think i am not fully understanding the relationship between the Jython wrapping and python?? maybe~~  
Very simple script i would like to run  
\<\>\<\>\<\>\<\>\<\>\<\>  
import pyodbc  
driver="{Sql Server Native Client 11.0}"  
server="127.0.0.1\SqlExpress"  
database="mydb"  
uid="sa"  
pwd="nonya"  
cnxn = pyodbc.connect('DRIVER=driver;SERVER=server;DATABASE=database;UID=uid;PWD=pwd')  
cursor = cnxn.cursor()  
cursor.execute("SELECT @@version")  
for row in cursor.fetchall():  
print('row=%r' %(row,))  
\<\>\<\>\<\>\<\>\<\>\<\>

Any help or funneling of thought is greatly appreciated

---

<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:** [February 10, 2023, 8:06pm UTC](https://forum.inductiveautomation.com/t/database-access-python-database-api-specification-v2-0/69713/2 "2023-02-10T20:06:46Z")

</div>

[Pymssql](https://www.pymssql.org/) is written in Cython, So I'm going to guess there are a lot of C dependencies that are unusable in Jython. Same for ODBC drivers in general, as they are also usually written in C,

---

<div class="post-metadata">

**Author:** ![Alan\_Cannon](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alan_cannon/32/31171_2.png) [@Alan\_Cannon](https://forum.inductiveautomation.com/u/Alan_Cannon)\
**Post date:** [February 10, 2023, 8:10pm UTC](https://forum.inductiveautomation.com/t/database-access-python-database-api-specification-v2-0/69713/3 "2023-02-10T20:10:35Z")

</div>

[https://docs.oracle.com/javase/tutorial/jdbc/overview/index.html](https://docs.oracle.com/javase/tutorial/jdbc/overview/index.html) ?????

---

<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:** [February 10, 2023, 8:12pm UTC](https://forum.inductiveautomation.com/t/database-access-python-database-api-specification-v2-0/69713/4 "2023-02-10T20:12:57Z")

</div>

JDBCs are written in Java. Not the same thing as ODBC, though the perform the same purpose.

---

<div class="post-metadata">

**Author:** ![Alan\_Cannon](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alan_cannon/32/31171_2.png) [@Alan\_Cannon](https://forum.inductiveautomation.com/u/Alan_Cannon)\
**Post date:** [February 10, 2023, 8:39pm UTC](https://forum.inductiveautomation.com/t/database-access-python-database-api-specification-v2-0/69713/5 "2023-02-10T20:39:46Z")

</div>

apologies. i guess what i mean to ask is could i travel down that Java db connection route and get to what i am looking for?

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [February 10, 2023, 9:13pm UTC](https://forum.inductiveautomation.com/t/database-access-python-database-api-specification-v2-0/69713/6 "2023-02-10T21:13:47Z")

</div>

This is what you have to do in other inferior SCADA products, I'm not sure why you would want to have to manage your own db connections if it's all nicely done for you? Unless for a learning experience?

---

<div class="post-metadata">

**Author:** ![Alan\_Cannon](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alan_cannon/32/31171_2.png) [@Alan\_Cannon](https://forum.inductiveautomation.com/u/Alan_Cannon)\
**Post date:** [February 10, 2023, 10:46pm UTC](https://forum.inductiveautomation.com/t/database-access-python-database-api-specification-v2-0/69713/7 "2023-02-10T22:46:04Z")

</div>

predominately learning Yes. I enjoy encapsulating ideas into processes and making code.  
Thanks,  
Alan

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [February 10, 2023, 11:25pm UTC](https://forum.inductiveautomation.com/t/database-access-python-database-api-specification-v2-0/69713/8 "2023-02-10T23:25:50Z")

</div>

You _can_ make JDBC connections from Jython code, but you'll need to provide the appropriate JDBC driver(s) yourself; Ignition's DB connections are deliberately made in an isolated classloader so that different drivers don't stomp on each other's classpaths. I wouldn't call this is a fruitful learning avenue, though. If you want to learn about DB connections on the JVM, it's going to be much easier to do it in plain Java in a module. If you want to make business code in Python, it's going to be much easier to let Ignition do the work of connection to your DB.

---

<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:** [February 10, 2023, 11:45pm UTC](https://forum.inductiveautomation.com/t/database-access-python-database-api-specification-v2-0/69713/9 "2023-02-10T23:45:17Z")

</div>

> [@paul-griffith](#):
>
> I wouldn't call this is a fruitful learning avenue, though.

Concur. The CPython techniques and libraries you might try to learn from will likely fail to run in Jython in Ignition, for a variety of reasons. Kiss your ORMs goodbye.

Learn to use Ignition's platform tools first. Then, after you've mastered the platform, you can dig under the hood. Most important is to learn standard SQL.

---

<div class="post-metadata">

**Author:** ![Alan\_Cannon](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alan_cannon/32/31171_2.png) [@Alan\_Cannon](https://forum.inductiveautomation.com/u/Alan_Cannon)\
**Post date:** [February 11, 2023, 12:21am UTC](https://forum.inductiveautomation.com/t/database-access-python-database-api-specification-v2-0/69713/10 "2023-02-11T00:21:58Z")

</div>

Ok maybe some example code of where i have been living will lend some direction on how i can migrate?  
[ADO and SQL Stroed procedures.txt](https://forum.inductiveautomation.com/uploads/short-url/caDNLZ1MRSEvN9aDKaUSt7weHPW.txt) (7.9 KB)

Thanks for the information btw. grey matter filling is always the best.

Alan

---

<div class="post-metadata">

**Author:** ![Alan\_Cannon](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/alan_cannon/32/31171_2.png) [@Alan\_Cannon](https://forum.inductiveautomation.com/u/Alan_Cannon)\
**Post date:** [February 11, 2023, 12:41am UTC](https://forum.inductiveautomation.com/t/database-access-python-database-api-specification-v2-0/69713/11 "2023-02-11T00:41:19Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/f/4f232dde26c4e2c1756ee26fd33cdac342b5f259.jpeg)  
my favorite book... 🙂
