[en] Database Connection String Replacement

Official translation unavailable. Translate this page with Google:

[en] Configuration file for Automation Service can include database connection string replacement commands.

[en] 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.

[en] Connection string replacement logic is defined in the DatabaseConnections.Config file that is located in the Automation system folder.

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

  2. [en] Create a file with the name DatabaseConnections.config.

  3. [en] 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>

    [en] 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.

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

  4. [en] Check the existing connection string in your labels, then change the <Replacement> content with the correct values.

    [en] 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.

    注意

    [en] 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. [en] 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. [en] Restart both Automation services after adding or editing the config files.

  7. [en] Repeat steps 1-6 on all computers that run Automation configurations where you want to replace database connection strings.

注意

[en] Database connection string replacement does not change connection strings in your label files. This procedure just overrides connection strings when printing from Automation.