<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <blockquote type="cite"><b style="color: rgb(0, 0, 0); font-family:
        "Times New Roman"; font-size: medium; font-style:
        normal; font-variant-ligatures: normal; font-variant-caps:
        normal; letter-spacing: normal; orphans: 2; text-align: start;
        text-indent: 0px; text-transform: none; white-space: normal;
        widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;
        text-decoration-thickness: initial; text-decoration-style:
        initial; text-decoration-color: initial;">Raymond Nijssen</b><br
        style="color: rgb(0, 0, 0); font-family: "Times New
        Roman"; font-size: medium; font-style: normal;
        font-variant-ligatures: normal; font-variant-caps: normal;
        font-weight: 400; letter-spacing: normal; orphans: 2;
        text-align: start; text-indent: 0px; text-transform: none;
        white-space: normal; widows: 2; word-spacing: 0px;
        -webkit-text-stroke-width: 0px; text-decoration-thickness:
        initial; text-decoration-style: initial; text-decoration-color:
        initial;">
      <i style="color: rgb(0, 0, 0); font-family: "Times New
        Roman"; font-size: medium; font-variant-ligatures: normal;
        font-variant-caps: normal; font-weight: 400; letter-spacing:
        normal; orphans: 2; text-align: start; text-indent: 0px;
        text-transform: none; white-space: normal; widows: 2;
        word-spacing: 0px; -webkit-text-stroke-width: 0px;
        text-decoration-thickness: initial; text-decoration-style:
        initial; text-decoration-color: initial;">Wed Dec 7 07:39:50 PST
        2022</i>
      <hr style="color: rgb(0, 0, 0); font-family: "Times New
        Roman"; font-size: medium; font-style: normal;
        font-variant-ligatures: normal; font-variant-caps: normal;
        font-weight: 400; letter-spacing: normal; orphans: 2;
        text-align: start; text-indent: 0px; text-transform: none;
        white-space: normal; widows: 2; word-spacing: 0px;
        -webkit-text-stroke-width: 0px; text-decoration-thickness:
        initial; text-decoration-style: initial; text-decoration-color:
        initial;">
      <pre style="white-space: pre-wrap; color: rgb(0, 0, 0); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">I'm trying to change the dataSourceUri of an existing layer
</pre>
    </blockquote>
    <br>
    Hi Raymond,<br>
    AFAIK you need to use setDataSource [1] directly on the layer an not
    setDataSourceUri on the data provider.<br>
    <br>
    E.g.:<br>
    <br>
    layer.setDataSource(new_ds, layer_name, 'ogr')<br>
    <br>
    <br>
    Best regards.<br>
    <br>
    Andrea<br>
    <br>
    [1]
<a class="moz-txt-link-freetext" href="https://qgis.org/pyqgis/master/core/QgsMapLayer.html#qgis.core.QgsMapLayer.setDataSource">https://qgis.org/pyqgis/master/core/QgsMapLayer.html#qgis.core.QgsMapLayer.setDataSource</a><br>
  </body>
</html>