
I am writing a python script to update datasource database connection. I've got it to work to update a datasource that is using Postgres database by updating Hostname, Port, Username and Password. Using this API Reference page
My question is, could I do the same to update a datasource connection that is connected to Oracle database since it requires to update Service name? From the API Reference page under update_connection, it only provides feature to only update serverAddress, serverPort, userName and password.
@mursid rahman
Hi, currently you can't do it using the Rest API or TSC.
As a workaround, you may use a combination of the REST API, and the Document API to make those changes. I have never done it, but I think it is possible. My suggested steps would be.
a. Download the tdsx or tds using TSC.
b. Edit the required connection fields using the document api:
https://tableau.github.io/document-api-python/docs/
However, the schema property is not documented, but taking a closer look from the source code, it seems it is supported:
https://github.com/tableau/document-api-python/blob/master/tableaudocumentapi/connection.py
This may be something like the following code, but like I said, I have not tested it. Also,
from tableaudocumentapi import Datasource
DS_FILENAME = "Ventas Test.tdsx"
DS_DIRECTORY = "D:\\Tableau Server\\Document API\\"
DS_PATH = DS_DIRECTORY + DS_FILENAME
NEW_DS_FILENAME = "New Ventas.tdsx"
sourceDS = Datasource.from_file(DS_PATH)
#Create a loop if neccesary if several connections in the TDSX/TDS
#sourceDS.connections[0].server = "MY-NEW-SERVER"
#sourceDS.connections[0].dbname = "NEW-DATABASE"
sourceDS.connections[0].schema = "NEW-SCHEMA"
#sourceDS.connections[0].service = "NEW-SERVICE"
#sourceDS.connections[0].port = "8040"
#sourceDS.connections[0].username = "NEW-USER"
sourceDS.save_as(DS_DIRECTORY + NEW_DS_FILENAME)
c. Once the file is saved, you may publish again your datasource using Rest API or Tableau Server Client. As always, before replacing your current datasource, do some tests.
I would like to have a complete code, however, I currently don't have it.
If this post resolves the question, would you be so kind to "Select as Best"?. This will help other users find the same answer/resolution and help community keep track of answered questions. Thank you.
Regards,
Diego Martinez
Tableau Visionary and Forums Ambassador