Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X
This Blog considers that you have already imported the Database Extension and Configured the Thing Template. If you have not done this already please see Steps to connecting to your Relational Database first.
Steps:
// NewDataBaseThingName is the String input for name the database thing to be created.
// MySqlServerUpdatedConfiguration is the Thing template with correct configuration
var params = {
name: NewDataBaseThingName /* STRING */,
description: NewDataBaseThingName /* STRING */,
thingTemplateName: "MySqlServerUpdatedConfiguration" /* THINGTEMPLATENAME */,
tags: undefined /* TAGS */
};
// no return
Resources["EntityServices"].CreateThing(params);
Things[NewDataBaseThingName].EnableThing();
Things[NewDataBaseThingName].RestartThing();
var datashapeParams = {
infoTableName : "InfoTable",
dataShapeName : "DatabaseConfigurationDS"
};// CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(DatabaseConfigurationDS)
var config = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape(datashapeParams);
var passwordParams = {
data: "DataBasePasswordHere" /* STRING */
};
// DatabaseConfigurationDS entry object
var newEntry = new Object();
newEntry.jDBCDriverClass= "com.mysql.jdbc.Driver"; // STRING
newEntry.jDBCConnectionURL = "jdbc:mysql://127.0.0.1:3306/<DatabaseNameHere>?allowMultiQueries=true"; // STRING
newEntry.connectionValidationString = "SELECT NOW()"; // STRING
newEntry.maxConnections = 100; // NUMBER
newEntry.userName = "DataBaseUserNameHere"; // STRING
newEntry.password = Resources["EncryptionServices"].EncryptPropertyValue(passwordParams); // PASSWORD
config.AddRow(newEntry);
var configurationTableParams = {
configurationTable: config /* INFOTABLE */,
persistent: true /* BOOLEAN */,
tableName: "ConnectionInfo" /* STRING */
};
// ThingNameForConfigurationUpdate is the input string for Thing Name whose configuration needs to be updated.
// no return
Things[ThingNameForConfigurationUpdate].SetConfigurationTable(configurationTableParams);
Things[ThingNameForConfigurationUpdate].RestartThing();
@ankigupta I am getting an error saying the configuration structure does not match.
Do not execute this line until configuration is set for that thing
Things[NewDataBaseThingName].RestartThing();