Announcement

Migration of this forum

Dear users of this forum,

we are pleased to inform you that we will be updating the software behind this forum in the near future.

Existing posts, users and categories will remain untouched.

Important:

  • Each user will need to reset their password.
  • Please select "I forgot my password".
  • Enter the email address you used to register in this forum.
  • You will receive an email with a link to set a new password.
  • Please choose a new (secure) password and confirm the process.

We will keep you informed in the pinned thread.

Kind regards,
Your ReportServer Team


Migration des Forums

Liebe Nutzer dieses Forums,

wir freuen uns, euch mitteilen zu können, dass wir in naher Zukunft die Software hinter diesem Forum aktualisieren werden.

Existierende Beiträge, Nutzer und Kategorien bleiben weiterhin bestehen!

Wichtig:

  • Jeder Nutzer muss sein Passwort neu vergeben.
  • Wählt dazu einfach "Ich habe mein Passwort vergessen".
  • Gebt die E-Mail-Adresse ein, mit der ihr registriert seid.
  • Ihr erhaltet eine E-Mail mit einem Link zur Passwortvergabe.
  • Bitte wählt ein neues (sicheres) Passwort und bestätigt den Vorgang.

Wir halten euch im angepinnten Beitrag auf dem Laufenden!

Mit vielen Grüßen
Euer ReportServer Team

#1 2020-10-14 18:32:50

unsi_2
Member
Registered: 2020-06-24

access datasource from script

Hi
i need a script (not a report) to connect to a database table, for using that data.

is there a built in object to obtain an existing datasource?
or have to be made using jdbc and setting the url connection?


kind regards

Offline

#2 2020-10-15 07:41:40

IF_Eduardo
Administrator
Registered: 2016-11-01
Website

Re: access datasource from script

Hi unsi_2,

you can access an existing datasource directly via script using the "connection" object, pls take a look here:
https://reportserver.net/en/tutorials/t … scripting/

If you don't create a script report, but you need a plain script, you can use groovy sql's constructs to connect to any database: https://docs.groovy-lang.org/latest/htm … l/Sql.html
or you can use plain JDBC calls too.

You can also get a datasource via DataSource Service: net.datenwerke.rs.core.service.datasourcemanager.DatasourceService.getDatasourceByName(String)
Pls check the services list in the API, available in the sourceforge downloads: https://sourceforge.net/projects/dw-rs/files/

Regards,
Eduardo

Offline

#3 2020-11-04 20:57:28

unsi_2
Member
Registered: 2020-06-24

Re: access datasource from script

many thanks Eduardo.

yes, it is a plain script, so for accessing a  RS datasource i imagine i cannot use groovy sql's constructs, only the objects of the API.

Offline

#4 2020-11-05 08:53:09

IF_Eduardo
Administrator
Registered: 2016-11-01
Website

Re: access datasource from script

Hi unsi_2,

you can access RS datasources and also use groovy sql constructs with these.

For example, you can access the query of a given dynamic list with id 1234 by:

import net.datenwerke.rs.base.service.reportengines.table.entities.TableReport;
import net.datenwerke.rs.core.service.reportmanager.ReportService;

/* getQuery from dynamic list */
ReportService reportService = GLOBALS.getRsService(ReportService.class);
TableReport tableReport = reportService.getReportByKey(1234);
String query = tableReport.getDatasourceContainer().getDatasourceConfig().getQuery();

so you can use plain groovy sql constructs with this query.

You can also get a connection of a given datasource MY_DS using the connection pool:

import net.datenwerke.rs.core.service.datasourcemanager.DatasourceService;
import net.datenwerke.rs.base.service.datasources.definitions.DatabaseDatasource;
import net.datenwerke.dbpool.DbPoolService;
import net.datenwerke.dbpool.config.ConnectionPoolConfig;
import java.sql.Connection;

DatasourceService datasourceService = GLOBALS.getRsService(DatasourceService.class);
DbPoolService dbPoolService = GLOBALS.getRsService(DbPoolService.class);
DatabaseDatasource ds = (DatabaseDatasource) datasourceService.getDatasourceByName("MY_DS");
ConnectionPoolConfig config = ds.getConnectionConfig();
Connection conn = dbPoolService.getConnection(config).get();

the connection (conn) can be used with groovy constructs, e.g. you can construct an SQL object using the given connection: https://docs.groovy-lang.org/latest/htm … onnection)

def sql = new Sql(conn)

Regards,
Eduardo

Offline

Board footer

Powered by FluxBB