12/14/2020 5:39 AM | |
Joined: 5/28/2016 Last visit: 4/26/2024 Posts: 3 Rating: (0) |
Hi Alex. Have you been able to solve your problem? I find myself in a situation similar to yours: I need to access a database in MS SQL Server. ------------------------------------------------------------------------------------------ |
Last edited by: Jen_Moderator at: 12/14/2020 12:14:31New subject after splitting |
|
2/7/2021 1:48 AM | |
Joined: 2/6/2021 Last visit: 4/1/2024 Posts: 9 Rating: (3) |
Hi,
Just use HMIRuntime.Database.CreateConnection(connectionString) to connect to the database. The Connection String is the same ODBC connections string you use in other applications. Please search the Microsoft MSDN to look up the format and features supported by this string. In the simplest case it is the name of a globally configured ODBC DataSource. More information about the Database object model can be found here: https://support.industry.siemens.com/cs/mdm/109773780?c=127688947979&lc=en-WW The connection.Execute() method is actually used for queries and inserts and supports also bound parameters which have to be put into the "values" parameters which is an array. The returned object from the async Execute() is a DatabaseResult object and not a ConnectionObject as mentioned in the docu. You can find 2 examples in the snippets. The following document contains some notes, but unfortunately the therein mentioned example is not available, yet: https://cache.industry.siemens.com/dl/files/536/109758536/att_1032976/v3/109758536_Unified_TipsScripting_V30_en.pdf The DatabaseConnection object can be put into a DataSet, so that it can be shared between the Action and Dynamics Script Engines in a screen. Michael |
2/7/2021 1:48 AM | |
Joined: 2/6/2021 Last visit: 4/1/2024 Posts: 9 Rating: (3) |
Hi,
Just use HMIRuntime.Database.CreateConnection(connectionString) to connect to the database. The Connection String is the same ODBC connections string you use in other applications. Please search the Microsoft MSDN to look up the format and features supported by this string. In the simplest case it is the name of a globally configured ODBC DataSource. More information about the Database object model can be found here: https://support.industry.siemens.com/cs/mdm/109773780?c=127688947979&lc=en-WW The connection.Execute() method is actually used for queries and inserts and supports also bound parameters which have to be put into the "values" parameters which is an array. The returned object from the async Execute() is a DatabaseResult object and not a ConnectionObject as mentioned in the docu. You can find 2 examples in the snippets. The following document contains some notes, but unfortunately the therein mentioned example is not available, yet: https://support.industry.siemens.com/cs/ww/en/view/109758536 The DatabaseConnection object can be put into a DataSet, so that it can be shared between the Action and Dynamics Script Engines in a screen. Michael |
Last edited by: Jen_Moderator at: 02/08/2021 11:02:55Optimized link. |
|
Follow us on