How to Connect EntityFramework Core to Multiple Google CloudSQL Instances Using CloudSQL Proxy?
up vote
2
down vote
favorite
I have 2 Postgres databases each in their own CloudSQL instance and a .NET web app running in GKE.
Goal: Connect web app utilizing EntityFramework Core to both CloudSQL instances using a single CloudSQL proxy.
I followed this setup and modified it following this S.O. answer.
There is an EF Core DbContext for each CloudSQL Instance.
The context connections are set using 2 environment variables:
new Context1(
optionsBuilder.UseNpgsql(Environment.GetEnvironmentVariable("CONNECTION_1"));
);
new Context2(
optionsBuilder.UseNpgsql(Environment.GetEnvironmentVariable("CONNECTION_2"));
);
The environment variables are set as:
CONNECTION_1 = "Host=127.0.0.1;Port=5432;Database=postgres;Username=postgres;Password=password"
CONNECTION_2 = "Host=127.0.0.1;Port=5432;Database=postgres;Username=postgres;Password=password2"
Current Behavior:
Context1 interacts with CloudSQL instance1 as normal.
Context2 throws PostgresException "42P01: relation my_Table_Name does not exist."
when trying to access a table.
Note: "my_Table_Name"
is a table in CloudSQL instance2
This leads me to believe Context2 is trying to access CloudSQL instance1 instead of instance2.
How can I point Context2 through the SQL Proxy to CloudSQL instance2?
entity-framework kubernetes google-cloud-sql cloud-sql-proxy
add a comment |
up vote
2
down vote
favorite
I have 2 Postgres databases each in their own CloudSQL instance and a .NET web app running in GKE.
Goal: Connect web app utilizing EntityFramework Core to both CloudSQL instances using a single CloudSQL proxy.
I followed this setup and modified it following this S.O. answer.
There is an EF Core DbContext for each CloudSQL Instance.
The context connections are set using 2 environment variables:
new Context1(
optionsBuilder.UseNpgsql(Environment.GetEnvironmentVariable("CONNECTION_1"));
);
new Context2(
optionsBuilder.UseNpgsql(Environment.GetEnvironmentVariable("CONNECTION_2"));
);
The environment variables are set as:
CONNECTION_1 = "Host=127.0.0.1;Port=5432;Database=postgres;Username=postgres;Password=password"
CONNECTION_2 = "Host=127.0.0.1;Port=5432;Database=postgres;Username=postgres;Password=password2"
Current Behavior:
Context1 interacts with CloudSQL instance1 as normal.
Context2 throws PostgresException "42P01: relation my_Table_Name does not exist."
when trying to access a table.
Note: "my_Table_Name"
is a table in CloudSQL instance2
This leads me to believe Context2 is trying to access CloudSQL instance1 instead of instance2.
How can I point Context2 through the SQL Proxy to CloudSQL instance2?
entity-framework kubernetes google-cloud-sql cloud-sql-proxy
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I have 2 Postgres databases each in their own CloudSQL instance and a .NET web app running in GKE.
Goal: Connect web app utilizing EntityFramework Core to both CloudSQL instances using a single CloudSQL proxy.
I followed this setup and modified it following this S.O. answer.
There is an EF Core DbContext for each CloudSQL Instance.
The context connections are set using 2 environment variables:
new Context1(
optionsBuilder.UseNpgsql(Environment.GetEnvironmentVariable("CONNECTION_1"));
);
new Context2(
optionsBuilder.UseNpgsql(Environment.GetEnvironmentVariable("CONNECTION_2"));
);
The environment variables are set as:
CONNECTION_1 = "Host=127.0.0.1;Port=5432;Database=postgres;Username=postgres;Password=password"
CONNECTION_2 = "Host=127.0.0.1;Port=5432;Database=postgres;Username=postgres;Password=password2"
Current Behavior:
Context1 interacts with CloudSQL instance1 as normal.
Context2 throws PostgresException "42P01: relation my_Table_Name does not exist."
when trying to access a table.
Note: "my_Table_Name"
is a table in CloudSQL instance2
This leads me to believe Context2 is trying to access CloudSQL instance1 instead of instance2.
How can I point Context2 through the SQL Proxy to CloudSQL instance2?
entity-framework kubernetes google-cloud-sql cloud-sql-proxy
I have 2 Postgres databases each in their own CloudSQL instance and a .NET web app running in GKE.
Goal: Connect web app utilizing EntityFramework Core to both CloudSQL instances using a single CloudSQL proxy.
I followed this setup and modified it following this S.O. answer.
There is an EF Core DbContext for each CloudSQL Instance.
The context connections are set using 2 environment variables:
new Context1(
optionsBuilder.UseNpgsql(Environment.GetEnvironmentVariable("CONNECTION_1"));
);
new Context2(
optionsBuilder.UseNpgsql(Environment.GetEnvironmentVariable("CONNECTION_2"));
);
The environment variables are set as:
CONNECTION_1 = "Host=127.0.0.1;Port=5432;Database=postgres;Username=postgres;Password=password"
CONNECTION_2 = "Host=127.0.0.1;Port=5432;Database=postgres;Username=postgres;Password=password2"
Current Behavior:
Context1 interacts with CloudSQL instance1 as normal.
Context2 throws PostgresException "42P01: relation my_Table_Name does not exist."
when trying to access a table.
Note: "my_Table_Name"
is a table in CloudSQL instance2
This leads me to believe Context2 is trying to access CloudSQL instance1 instead of instance2.
How can I point Context2 through the SQL Proxy to CloudSQL instance2?
entity-framework kubernetes google-cloud-sql cloud-sql-proxy
entity-framework kubernetes google-cloud-sql cloud-sql-proxy
edited Nov 8 at 22:19
Rico
24.4k94864
24.4k94864
asked Nov 8 at 21:38
msauce4
111
111
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
Basically this:
CONNECTION_1 = "Host=127.0.0.1;Port=5432;Database=postgres;Username=postgres;Password=password"
CONNECTION_2 = "Host=127.0.0.1;Port=5432;Database=postgres;Username=postgres;Password=password2"
means that you are connecting to the exact same Cloud SQL instance, with just two different passwords (same username). Not sure how CONNECTION_2 might even connect to the Cloud SQL instance1 though.
You would want to have something like this:
CONNECTION_1 = "Host=127.0.0.1;Port=5432;Database=postgres;Username=postgres;Password=password"
CONNECTION_2 = "Host=127.0.0.1;Port=5433;Database=postgres;Username=postgres;Password=password2"
and on your cloud-proxy command line (running on the same pod):
-instances=project:region:sqlinstance1=tcp:5432,project:region:sqlinstance2=tcp:5433
Matching the ports to those defined in the deployment.yaml didn't work either. Any other ideas?
– msauce4
Nov 9 at 1:15
Try shelling into the pod and debug from there
– Rico
Nov 9 at 2:16
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Basically this:
CONNECTION_1 = "Host=127.0.0.1;Port=5432;Database=postgres;Username=postgres;Password=password"
CONNECTION_2 = "Host=127.0.0.1;Port=5432;Database=postgres;Username=postgres;Password=password2"
means that you are connecting to the exact same Cloud SQL instance, with just two different passwords (same username). Not sure how CONNECTION_2 might even connect to the Cloud SQL instance1 though.
You would want to have something like this:
CONNECTION_1 = "Host=127.0.0.1;Port=5432;Database=postgres;Username=postgres;Password=password"
CONNECTION_2 = "Host=127.0.0.1;Port=5433;Database=postgres;Username=postgres;Password=password2"
and on your cloud-proxy command line (running on the same pod):
-instances=project:region:sqlinstance1=tcp:5432,project:region:sqlinstance2=tcp:5433
Matching the ports to those defined in the deployment.yaml didn't work either. Any other ideas?
– msauce4
Nov 9 at 1:15
Try shelling into the pod and debug from there
– Rico
Nov 9 at 2:16
add a comment |
up vote
0
down vote
Basically this:
CONNECTION_1 = "Host=127.0.0.1;Port=5432;Database=postgres;Username=postgres;Password=password"
CONNECTION_2 = "Host=127.0.0.1;Port=5432;Database=postgres;Username=postgres;Password=password2"
means that you are connecting to the exact same Cloud SQL instance, with just two different passwords (same username). Not sure how CONNECTION_2 might even connect to the Cloud SQL instance1 though.
You would want to have something like this:
CONNECTION_1 = "Host=127.0.0.1;Port=5432;Database=postgres;Username=postgres;Password=password"
CONNECTION_2 = "Host=127.0.0.1;Port=5433;Database=postgres;Username=postgres;Password=password2"
and on your cloud-proxy command line (running on the same pod):
-instances=project:region:sqlinstance1=tcp:5432,project:region:sqlinstance2=tcp:5433
Matching the ports to those defined in the deployment.yaml didn't work either. Any other ideas?
– msauce4
Nov 9 at 1:15
Try shelling into the pod and debug from there
– Rico
Nov 9 at 2:16
add a comment |
up vote
0
down vote
up vote
0
down vote
Basically this:
CONNECTION_1 = "Host=127.0.0.1;Port=5432;Database=postgres;Username=postgres;Password=password"
CONNECTION_2 = "Host=127.0.0.1;Port=5432;Database=postgres;Username=postgres;Password=password2"
means that you are connecting to the exact same Cloud SQL instance, with just two different passwords (same username). Not sure how CONNECTION_2 might even connect to the Cloud SQL instance1 though.
You would want to have something like this:
CONNECTION_1 = "Host=127.0.0.1;Port=5432;Database=postgres;Username=postgres;Password=password"
CONNECTION_2 = "Host=127.0.0.1;Port=5433;Database=postgres;Username=postgres;Password=password2"
and on your cloud-proxy command line (running on the same pod):
-instances=project:region:sqlinstance1=tcp:5432,project:region:sqlinstance2=tcp:5433
Basically this:
CONNECTION_1 = "Host=127.0.0.1;Port=5432;Database=postgres;Username=postgres;Password=password"
CONNECTION_2 = "Host=127.0.0.1;Port=5432;Database=postgres;Username=postgres;Password=password2"
means that you are connecting to the exact same Cloud SQL instance, with just two different passwords (same username). Not sure how CONNECTION_2 might even connect to the Cloud SQL instance1 though.
You would want to have something like this:
CONNECTION_1 = "Host=127.0.0.1;Port=5432;Database=postgres;Username=postgres;Password=password"
CONNECTION_2 = "Host=127.0.0.1;Port=5433;Database=postgres;Username=postgres;Password=password2"
and on your cloud-proxy command line (running on the same pod):
-instances=project:region:sqlinstance1=tcp:5432,project:region:sqlinstance2=tcp:5433
answered Nov 8 at 22:45
Rico
24.4k94864
24.4k94864
Matching the ports to those defined in the deployment.yaml didn't work either. Any other ideas?
– msauce4
Nov 9 at 1:15
Try shelling into the pod and debug from there
– Rico
Nov 9 at 2:16
add a comment |
Matching the ports to those defined in the deployment.yaml didn't work either. Any other ideas?
– msauce4
Nov 9 at 1:15
Try shelling into the pod and debug from there
– Rico
Nov 9 at 2:16
Matching the ports to those defined in the deployment.yaml didn't work either. Any other ideas?
– msauce4
Nov 9 at 1:15
Matching the ports to those defined in the deployment.yaml didn't work either. Any other ideas?
– msauce4
Nov 9 at 1:15
Try shelling into the pod and debug from there
– Rico
Nov 9 at 2:16
Try shelling into the pod and debug from there
– Rico
Nov 9 at 2:16
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53216527%2fhow-to-connect-entityframework-core-to-multiple-google-cloudsql-instances-using%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown