Set parameters on a Synapse Analytics dataset using the Azure SDK

Charlie S 31 Reputation points
2022-01-29T02:07:54.547+00:00

I am trying to create a parameterized dataset in Synapse Analytics using the Azure SDK. If I remove line 22 below ( delimitedDataset.Parameters = myParms;), the dataset is successfully created.

Line 22 fails as the property 'Dataset.Parameters' is read only.

How can I set the parameters property on a Dataset with the Azure SDK?

    string dataSetName = "MyDatasetName";
    DatasetClient dsClient = new DatasetClient(endpoint: workspaceDevelopmentEndpoint, credential: new DefaultAzureCredential());
    LinkedServiceReferenceType lsRefType = new("LinkedServiceReference");
    LinkedServiceReference lsRef = new(lsRefType, landingAreaLinkedServiceName);

    DelimitedTextDataset delimitedDataset = new(lsRef);
    delimitedDataset.ColumnDelimiter = ",";
    delimitedDataset.EscapeChar = "\\";
    delimitedDataset.QuoteChar = "\"";
    delimitedDataset.FirstRowAsHeader = true;
    delimitedDataset.Location = new AzureBlobFSLocation();
    AzureBlobFSLocation tmpLocation = new();
    tmpLocation.FileSystem = "data";
    delimitedDataset.Location = tmpLocation;

    var myParms = new Dictionary<string, ParameterSpecification>
    {
        { "folderPath", new ParameterSpecification(ParameterType.String) },
        { "fileName", new ParameterSpecification(ParameterType.String) },
    };

    delimitedDataset.Parameters = myParms; 

    DatasetResource dsr = new(delimitedDataset);
    DatasetCreateOrUpdateDatasetOperation dsOperation = dsClient.StartCreateOrUpdateDataset(dataSetName, dsr);
    Azure.Response<DatasetResource> createdDataset = await dsOperation.WaitForCompletionAsync();
Azure Synapse Analytics
Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
{count} votes

Answer accepted by question author
  1. Saurabh Sharma 23,866 Reputation points Microsoft Employee Moderator
    2022-02-07T19:33:56.18+00:00

    Hi @CharlieSchafer-2122,

    You were not able to set the parameters of a DelimitedTextDataSet using the property 'Dataset.Parameters' as this property is read-only. So, in order to add parameters to your dataset either you need to pass the parameters in the constructor as described here or you need to use delimitedDataset.Parameters.Add function in your code. For example - below code adds folderPath and fileName property to a dataset using .Add function.

    DelimitedTextDataset delimitedDataset = new(lsRef);  
    delimitedDataset.Parameters.Add("folderPath", new ParameterSpecification(ParameterType.String));  
    delimitedDataset.Parameters.Add("fileName", new ParameterSpecification(ParameterType.String));  
          
    DatasetResource dsr = new(delimitedDataset);  
    DatasetCreateOrUpdateDatasetOperation dsOperation = dsClient.StartCreateOrUpdateDataset(dataSetName, dsr);  
    Azure.Response<DatasetResource> createdDataset = await dsOperation.WaitForCompletionAsync();  
    

    Result:
    172006-image.png

    Hope this helps.
    Please let me know if you have any questions.

    Thanks
    Saurabh

    ----------

    Please do not forget to "Accept the answer" wherever the information provided helps you to help others in the community.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.