Multiple pages app connect to same sql database

Hi,

How to connect to the same sql database for multiple pages app in app.py?

Currently, I attached the connection code to every single page. :joy:

Hello @beginof,

You can either do that or create a utils function that returns the connection and import it into each of the pages.

can you share the sample code?

Sure.

utils/conn.py

import pyodbc

conn = pyodbc.connect(your connection)

page

from utils/conn import conn

You can get fancier and return different things with a function, and so forth, especially if you have multiple databases. :grin:

1 Like

Thanks @jinnyzor :grinning: