Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NPGSQL with .netCore how to login to schema not just to database

Tags:

c#

postgresql

This is my NPGSQL connection string

{
    "ConnectionStrings": {     
        "DataAccessPostgreSqlProvider":  "User ID=damienbod;Password=1234;Host=localhost;Port=5432;Database=damienbod;Pooling=true;"
        }
    }
}

taken from here: https://damienbod.com/2016/01/11/asp-net-5-with-postgresql-and-entity-framework-7/

But I am using schemas under my Postgres database. How to connect to idsrv4 schema?

like image 449
mbrc Avatar asked Sep 11 '16 19:09

mbrc


People also ask

How do I connect to Npgsql?

Connections can be instantiated directly, and must then be opened before they can be used: var connectionString = "Host=myserver;Username=mylogin;Password=mypass;Database=mydatabase"; await using var conn = new NpgsqlConnection(connectionString); await conn. OpenAsync();

How do I specify schema name in Postgres JDBC URL?

there is added support for specifying the current schema using URL. With @ClassRule, we create an instance of PostgreSQL database container. Next, in the setup method, create a connection to that database and create the required objects. To change the default schema, we need to specify the currentSchema parameter.


1 Answers

You can also specify the search path in the connection string:

{
"ConnectionStrings": {     
    "DataAccessPostgreSqlProvider":  "User ID=damienbod;Password=1234;Host=localhost;Port=5432;Database=damienbod;Pooling=true;SearchPath=your_search_path;"
    }
}
like image 148
Manuel Montoya Avatar answered Sep 22 '22 14:09

Manuel Montoya