title: SSAS TOM - how to access datasource for PowerBI model
body: <p>I'm using TOM to interrogate and manipulate a PBIX file open in Power BI.  The PBIX file uses a parameter to set the connection string to the sql database that sources the data for the model.  I cannot figure out how to return the datasource from the metadata for the file.  Here is the code I have:</p>
  <pre><code>//this all works fine
  Server server = new Server(); //from Microsoft.AnalysisServices.Tabular library
  server.connect(connStr); //defined elsewhere
  Model model = server.Databases[0].Model; //I am using this model to loop through tables and columns and it works fine
  
  //these do not
  model.DataSources
  model.DataSources[0]
  model.DataSources.find...
  
  model.datasources.tostring() returns Microsoft.AnalysisServices.Tabular.DataSourcesCollection
  </code></pre>
  <p>So it seems I have a collection, but trying to reference an item in the collection using DataSources[0] throws a parameter out of bounds error, which sort of makes sense in that the   DataSources.count property returns 0 (which seems wrong -&gt;).  In looking at the datasources in the model via PowerBI desktop, the one I want is in there, fully formed with the database name filled from the parameter.</p>
  <p>Can anyone give me a clue as to what's going on here or how I can get the datasource from the model?</p>