Forum Discussion

alexmorgan's avatar
alexmorgan
Regular Visitor
5 years ago

Error al crear datasets

I have the following code and when I start creating a new database on the line: writer s request. GetRequestStream())

I skip the following error:

IOException: Cannot write data from to transport connection: An existing connection has been forced to be interrupted by the remote host.

SocketException: An existing connection has been forced to be interrupted by the remote host


Do you know how it can be solvent?

According to the powerbi forums the code is correct and 4 months ago it worked

 #region Create a dataset in Power BI
        private static void CreateDataset()
        {
            //TODO: Add using System.Net and using System.IO

string powerBIDatasetsApiUrl = "https://api.powerbi.com/v1.0/myorg/datasets";
            //POST web request to create a dataset.
            //To create a Dataset in a group, use the Groups uri: https://api.PowerBI.com/v1.0/myorg/groups/{group_id}/datasets
            HttpWebRequest request = System.Net.WebRequest.Create(powerBIDatasetsApiUrl) as System.Net.HttpWebRequest;
            request. KeepAlive = true;
            request. Method = "POST";
            request. ContentLength = 0;
            request. ContentType = "application/json";

//Add token to the request header
            request. Headers.Add("Authorization", String.Format("Bearer {0}", token));

//Create dataset JSON for POST request
            string datasetJson = "{\"name\": \"SalesMarketing\", \"tables\": " +
                "[{\"name\": \"Product\", \"columns\": " +
                "[{ \"name\": \"ProductID\", \"dataType\": \"Int64\"}, " +
                "{ \"name\": \"Name\", \"dataType\": \"string\"}, " +
                "{ \"name\": \"Category\", \"dataType\": \"string\"}," +
                "{ \"name\": \"IsCompete\", \"dataType\": \"bool\"}," +
                "{ \"name\": \"ManufacturedOn\", \"dataType\": \"DateTime\"}" +
                "]}]}";

//POST web request
            byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(datasetJson);
            request. ContentLength = byteArray.Length;

//Write JSON byte[] into a Stream
            using (Stream writer = request. GetRequestStream())            
{ writer. Write(byteArray, 0, byteArray.Length); var response = (HttpWebResponse)request. GetResponse(); } } #endregion } }

1 Reply

  • v-alq-msft's avatar
    v-alq-msft
    Icon for Community Support rankCommunity Support

    Hi, alexmorgan 

     

    I am not very familiar with the codes. You may refer to the document to see if Power BI Rest API helps.

     

    Best Regards

    Allan

     

    If this post helps,then consider Accepting it as the solution to help other members find it faster.