Configuration file for Automation Service can include database connection string replacement commands.
You can configure the service to replace certain parts of a connection string while the trigger is running. This enables a single instance of Automation to run the same configuration, but actually use a different database server for database related functionality. This allows the user to configure triggers in development environments and run them in production environments without any changes in the configuration.
Connection string replacement logic is defined in the DatabaseConnections.Config
file that is located in the Automation system folder.
-
Open the Automation system folder
%PROGRAMDATA%\NiceLabel\NiceLabel 10
-
Create a file with the name
DatabaseConnections.config
. -
Open the newly created file DatabaseConnections.config in a text editor and enter the sample content:
<?xml version="1.0" encoding="UTF-8"?> <DatabaseConnectionReplacements> <Replacement> <From>Data Source=mySQLServer</From> <To>Data Source=NEW_mySQLServer</To> </Replacement> <Replacement> <From>Initial Catalog=myDatabase</From> <To>Initial Catalog=NEW_myDatabase</To> </Replacement> </DatabaseConnectionReplacements>
This sample XML is an example, where an existing trigger contains a connection to the Microsoft SQL server named
mySQLServer
and the database namedmyDatabase
. You want to update the connection string to use the databaseNEW_myDatabase
on the serverNEW_mySQLServer
.Two replacement elements have to be defined – one to change the server name and one to change the database name.
-
Check the existing connection string in your labels, then change the
<Replacement>
content with the correct values.Configuration file defines from-to pairs using its XML structure. The
<Replacement>
element contains one<From>
and one<To>
element. During trigger execution, the "from" string is replaced with the "to" string. You can define as many<Replacement>
elements as necessary.Note
Some connection strings use Server=servername while others use Data Source=servername. If you use the same database, you don't have to enter database names.
-
Edit your
product.config
file that is located in%PROGRAMDATA%\NiceLabel\NiceLabel 10
. Add the element/Common/General/UseLocalReplacementStrings
and assign valueTrue
:<?xml version="1.0" encoding="utf-8"?> <configuration> <Common> <General> ... <UseLocalReplacementStrings>True</UseLocalReplacementStrings> </General> </Common> ... </configuration>
-
Restart both Automation services after adding or editing the config files.
-
Repeat steps 1-6 on all computers that run Automation configurations where you want to replace database connection strings.
Note
Database connection string replacement does not change connection strings in your label files. This procedure just overrides connection strings when printing from Automation.