ERPNext Connect with MS-Sql Server on Ubuntu 22.04.5 LTS with Window
Sun Mar 23 2025 11:43:53 GMT+0000 (Coordinated Universal Time)
Saved by
@Taimoor
Step:-1. //Create Virtual Environment and Install Dependencies
sudo apt update
sudo apt install python3.10-venv
python3 -m venv venv
source venv/bin/activate
pip install pyodbc requests
Step:-2. //Install ODBC Driver for Microsoft SQL Server
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
curl https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install -y msodbcsql17 unixodbc-dev
odbcinst -q -d -n "ODBC Driver 17 for SQL Server"
Step:-3. //Configure SQL Server
--Ensure that your SQL Server allows remote connections and
--you can access it from your Ubuntu environment.
// Install ODBC Driver for SQL Server:
sudo apt-get install unixodbc-dev msodbcsql17
Step:-4. //Generate API Key and API Secret for ERPNext
1-Log in to ERPNext as an Administrator.
2-Generate an API Key and Secret by going to User Settings and creating an API key.
3-Save these credentials securely, as you will use them to authenticate the API requests in the script.
Step:-5. //Create a python file and Write the Python Script
Create a Python file called erpnext_sql.py in your desired directory.
You can download or copy the provided code from the Bellow link.
https://www.thiscodeworks.com/embed/66f3fc60f4dcb900149d8681
5.1. //Using nano to Create and Edit the File:
nano erpnext_sql.py
//Copy data from the above link and Configure your API, SQL Setting, and Save it
To save and exit:
Press CTRL + O to save the file.
Press Enter to confirm the filename.
Press CTRL + X to exit nano.
Customize the Python script as necessary to suit your SQL Server data import logic and ERPNext API interactions.
Step:-6. Create a file "last_imported_timestamp.txt"
# Define path to the timestamp file
timestamp_file_path = '/home/erpnext/last_imported_timestamp.txt'
# Default timestamp value
default_timestamp = '2000-01-01 00:00:00'
Step:-7. Run the Python Script Manually
//"python3 file_name"
python3 erpnext_sql.py
-----------------------------
source venv/bin/activate
python3 erpnext_sql.py
content_copyCOPY
Comments