Database Connection String Replacement

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.

  1. Open the Automation system folder %PROGRAMDATA%\NiceLabel\NiceLabel 10

  2. Create a file with the name DatabaseConnections.config.

  3. 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 named myDatabase. You want to update the connection string to use the database NEW_myDatabase on the server NEW_mySQLServer.

    Two replacement elements have to be defined – one to change the server name and one to change the database name.

  4. 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.

  5. Edit your product.config file that is located in %PROGRAMDATA%\NiceLabel\NiceLabel 10. Add the element /Common/General/UseLocalReplacementStrings and assign value True:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
        <Common>
            <General>
            ...
                <UseLocalReplacementStrings>True</UseLocalReplacementStrings>
            </General>
        </Common>
    ...
    </configuration>
  6. Restart both Automation services after adding or editing the config files.

  7. 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.