# Do reconnect node-red-node-sqlite by event

**URL:** <https://discourse.nodered.org/t/do-reconnect-node-red-node-sqlite-by-event/90724>\
**Category:** General\
**Created:** [5 September 2024 06:38 UTC](https://discourse.nodered.org/t/do-reconnect-node-red-node-sqlite-by-event/90724 "2024-09-05T06:38:22Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![buschhardtt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/buschhardtt/32/94239_2.png) [@buschhardtt](https://discourse.nodered.org/u/buschhardtt)\
**Post date:** [5 September 2024 06:38 UTC](https://discourse.nodered.org/t/do-reconnect-node-red-node-sqlite-by-event/90724/1 "2024-09-05T06:38:23Z")

</div>

Hallo,  
when I connect to a sqlite-database and I want to change the databasefile (same filename), I can not reconnect to the new file content. Is there a way to reconnect without restart nodered?

Thank You

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [5 September 2024 08:36 UTC](https://discourse.nodered.org/t/do-reconnect-node-red-node-sqlite-by-event/90724/2 "2024-09-05T08:36:07Z")

</div>

Welcome to the forum @buschhardtt

Can you explain what you mean by "change the databasefile (same filename)"?  
Are you actually replacing the db file while Node-red is connected to it?

Will it reconnect if you do a full redeploy?

---

<div class="post-metadata">

**Author:** ![buschhardtt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/buschhardtt/32/94239_2.png) [@buschhardtt](https://discourse.nodered.org/u/buschhardtt)\
**Post date:** [5 September 2024 13:45 UTC](https://discourse.nodered.org/t/do-reconnect-node-red-node-sqlite-by-event/90724/3 "2024-09-05T13:45:38Z")

</div>

Hello jbudd,

I use the calibre database (sqlite: metadata.db). After I synchronize calibre files, I want to reconnect the database-connection to use the new datas.  
The correct way would be: close db-connection, synchronize, connect db-connection  
But I dont find close and connect/reconnect

Yes after a full redeploy the db is reconnected.

Bye

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [5 September 2024 18:40 UTC](https://discourse.nodered.org/t/do-reconnect-node-red-node-sqlite-by-event/90724/4 "2024-09-05T18:40:43Z")

</div>

I tried closing the db connection using node-red-node-sqlite but could not make it work.

Your best approach might be to access the database via an external program such as Python.

The sqlite library for python 3 does have access to database connect and close.

You could start the python process via Node-red's daemon node, which allows you to pass data backwards and forwards.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [6 September 2024 12:02 UTC](https://discourse.nodered.org/t/do-reconnect-node-red-node-sqlite-by-event/90724/5 "2024-09-06T12:02:46Z")

</div>

Why don’t you just use two SQLite nodes? You could add the name of the db to the msg as msg.database. That will indicate which node to go to, so you add a switch node look at the msg.database and use that to route the msg to the correct SQLite node.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [6 September 2024 13:22 UTC](https://discourse.nodered.org/t/do-reconnect-node-red-node-sqlite-by-event/90724/6 "2024-09-06T13:22:47Z")

</div>

Calibre is mainly written in Python. It keeps an in-memory cache of the db when it is running so it isn't really safe to do anything with the db while Calibre is running. However, they do provide an API. Details here:

[https://manual.calibre-ebook.com/develop.html](https://manual.calibre-ebook.com/develop.html)

Better still though would be to run the calibre-server and access the data using the REST API.

Oh, and I didn't realise that there is a 3rd method. It provides a command-line tool `calibredb`.

---

<div class="post-metadata">

**Author:** ![buschhardtt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/buschhardtt/32/94239_2.png) [@buschhardtt](https://discourse.nodered.org/u/buschhardtt)\
**Post date:** [11 September 2024 06:34 UTC](https://discourse.nodered.org/t/do-reconnect-node-red-node-sqlite-by-event/90724/7 "2024-09-11T06:34:20Z")

</div>

Thank you for the tip about calibredb. Here's a simple workflow using calibredb for anyone interested in this topic.

https://flows.nodered.org/flow/78887fa0df95e1c31f436c7f38afcee7/share

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [25 September 2024 06:34 UTC](https://discourse.nodered.org/t/do-reconnect-node-red-node-sqlite-by-event/90724/8 "2024-09-25T06:34:26Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
