Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

.NET Core Blazor Server cannot access to Cloud SQL in Cloud Run

$
0
0

I have several applications in my cloud run using PHP and .NET Core. My existing ASP.NET Core Web API does not have an issue when trying to connect with my Cloud SQL (MySQL). The access with either Public IP or Private IP with VPC works just fine. However, I tried another app in Cloud Run with Blazor Server on .NET Core, connecting to the same database server is not working.

This is my connection string

"DefaultConnection": "Server=/cloudsql/my-project-id:asia-southeast2:my-cloud-sql; User ID=userDb; Password=verysecret; Database=mydb_dev"

I tried to connect with VPC either, creating a VPC serverless and attach it to my Blazor app.

So my connection string becomes like this:

"DefaultConnection": "Server=10.0.0.8; User ID=userDb; Password=verysecret; Database=mydb_dev"

The only time it works is when I changed the authorized networks from Cloud SQL to allow any IP Addresses (0.0.0.0/0). I'm using Entity Framework Core with package Pomelo.EntityFrameworkCore.Mysql which is works with my ASP.NET Core Web API on another Cloud Run.

below is my dockerfile, in case if it's related

# Stage 1: Build the Blazor Server appFROM mcr.microsoft.com/dotnet/sdk:8.0 AS build-envWORKDIR /app# Copy csproj and restore dependenciesCOPY *.csproj ./RUN dotnet restore# Copy all the source code and build the appCOPY . ./RUN dotnet publish -c Release -o /out /p:UseAppHost=falseFROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base# Expose port 80USER appEXPOSE 8080EXPOSE 8081# Copy published filesCOPY --from=build-env /out .ENTRYPOINT ["dotnet", "MyBlazorApp.dll"]

Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>