Sign up to take part
Registered users can ask their own questions, contribute to discussions, and be part of the Community!
Registered users can ask their own questions, contribute to discussions, and be part of the Community!
Can I use Python to change a SQL Server dataset connection?
import dataiku
client = dataiku.api_client()
project = client.get_default_project()
dataset = project.get_dataset('mysqldataset')
settings = dataset.get_settings()
print(settings.get_raw_params()['connection']) # gives the current connection
..how can I change the connection only?
a method such as settings.set_connection() would be handy
Hi @JohnB
Can you try this? This will replace CONNECTION_TO_REPLACE with NEW_CONNECTION for all datasets within the current project.
import dataiku
client = dataiku.api_client()
project = client.get_default_project()
for dataset in project.list_datasets(as_type="objects"):
settings = dataset.get_settings()
if settings.get_raw()["managed"] and settings.get_raw_params().get("connection", None) == "CONNECTION_TO_REPLACE":
settings.get_raw_params()["connection"] = "NEW_CONNECTION"
settings.save()
Hi @JohnB
Can you try this? This will replace CONNECTION_TO_REPLACE with NEW_CONNECTION for all datasets within the current project.
import dataiku
client = dataiku.api_client()
project = client.get_default_project()
for dataset in project.list_datasets(as_type="objects"):
settings = dataset.get_settings()
if settings.get_raw()["managed"] and settings.get_raw_params().get("connection", None) == "CONNECTION_TO_REPLACE":
settings.get_raw_params()["connection"] = "NEW_CONNECTION"
settings.save()
Hi Sergey,
That works well.
I wasn't aware that this line would change the original settings object:
settings.get_raw_params()["connection"] = "NEW_CONNECTION"
Thanks!
John