Change Database Connection Tutorial

Description

Changing between databases on the fly without the need to restart SambaPOS with a push of a button. Had this request from a client (to check old reports, accounts etc) so decided to share it on the forum since there is no actual tutorial for this.

Requirements:

  1. SQL Server Express 2014 - 2017

  2. Custom Navigation Screen

  3. SambaPOS 5.3.0 (tested on it)

Tutorial:

Actions

Action - Change Database Connection

Name: Change Database Connection
Save To Local Settings: [:SaveToLocalSettings T/F]
user Pin: [:UserPIN]
Reset To Default Connection: [:ResetToDefaultConnection T/F]


Action - Logout User
image

Name: Logout User
Reset Cache: True
Logout Admin: True


Automation Commands

Automation Command - SQL Connection String

Name: SQL Connection String
Category: Navigation
Button Header: SQL String


Navigation Settings Template:

<size 46><sym></sym></size>

<size 48><bold>SQL String</bold></size>


Rules

Rule - SQL Connection String

Name: AMC SQL String
Event Name: Automation Command Executed
Custom Constraints: Execute rule if Matches
Automation Command Name Equals SQL Connection String

Actions:

Change Database Connection
Constraint:
String:

Data Source=DESKTOP-TFJ218C\SAMBAPOS; User Id=sa; Password=sambapos; Database=[?Database;;{REPORT SQL DETAILS:SELECT name FROM master.sys.databases WHERE database_id > 4 ORDER BY name:F.name::|};OCS;]

SaveToLocalSeetings T/F: True
User PIN:
ResetToDefaultConnection T/F:

Execute Automation Command
Constraint:
Command Name: Logout User


Rule - Logout User

Name: AMC Logout User
Event Name: Automation Command Executed
Custom Constraints: Execute rule if Matches
Automation Command Name Equals Logout User

Actions:

Logout User
Constraint:


Import File

Change SQL Connection Button.zip (1.3 KB)

3 Likes

You should know it may cause you to have to reactivate licenses. But great tutorial.

1 Like

Yeah I was thinking the same. I did something similar before for switching db on a demo system, and it will go back to trial after doing it a few times.

I dont think my client will use it very often but more so than him, I will use when I copy scripts, reports & other stuff from database to database. Cuts down those 10-20 seconds of restarting Samba.

2 Likes

I also need to warn you that if license is not a fresh license… if database had a license on it at some point but it got messed up due to switching databases you cant just press activate again. You will need to go through a process of logging out, uninstalling license, clear license key, close sambapos, reopen sambapos install license, close sambapos, restart sambapos, login, close sambapos restart sambapos, and then press activate.

Typically the smooth ability to just press activate works on fresh installs where a license was never applied to a database. I am not trying to discourage this tutorial I just want to make sure anyone following it understands what could happen.

1 Like

Yes I have used this type process in dev stuff for a long time now. It really helps and you built a nice tutorial.

1 Like

Eh, something to fiddle with :slight_smile: