1

When I run this C# code from MS Visual Studio to connect with Power BI service I get Error: The connection either timed out or was lost. What could be wrong? I checked the XMLA endpoints in Power BI service and are all enabled. The code fails when I try to connect to the server with server.Connect. I use the access token with no issues to run other Power BI APIs via HTTP (not powerbi://).

[ApiController]
[Route("api/[controller]")]
public class XmlaController : ControllerBase
{
    [HttpPost]
    public IActionResult PostXmla([FromBody] XmlaRequest request)
    {
        try
        {
            Console.WriteLine("Received XMLA request from Java");

            Server server = new Server();

            // Connect to Power BI via XMLA
            Console.WriteLine(request.accessToken);
            server.Connect($"DataSource={"powerbi://api.powerbi.com/v1.0/myorg/visualbank"};", request.accessToken);
   

            Console.WriteLine("Connected to Power BI service");

            // Execute XMLA script
            server.Execute(request.xmlaScript);

            server.Disconnect();

            return Ok("XMLA script executed successfully.");
        }
        catch (Exception ex)
        {
            Console.WriteLine($"Error: {ex.Message}");
            return StatusCode(500, $"Failed to execute XMLA script: {ex.Message}");
        }
    }
}
1
  • Unless the report itself is taking an excessive amount of time to respond, then most likely you have a network or firewall-related issue. We can't tell you anything about that just from staring at some code. Commented Jun 3 at 10:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.