Skip to content

GetSchema uses new connections instead of current #543

Closed

Description

@akrock

The fact that GetSchema is creating a new connection instead re-using the current connection is causing some headaches due to a specific configuration that my company is attempting to use.

Our connections are being established with one user, and then using "SET ROLE" to elevate the user to a different role that has access to more tables. The issue comes into play because since a new connection is created instead of re-using the current connection it is not receiving these elevated permissions and therefore GetSchema does not produce the expected results.

Is there a specific reason why GetSchema creates a new connection even if the current NpgsqlConnection instance on which the method is called is already connected to the database?

Activity

  1. roji commented on Mar 19, 2015

    @roji
    Member

    That's a pretty good question, I can't see any reason at all for this behavior. I checked SqlClient and trying to call GetSchema() while a reader is open fails, meaning that it doesn't open an additional connection.

    @franciscojunior, any ideas why GetSchema() does this? If not I can change the behavior to use the current connection.

  2. added this to the 2.2.6 milestone on Mar 19, 2015
  3. self-assigned this
    on Mar 19, 2015
  4. franciscojunior commented on Mar 19, 2015

    @franciscojunior
    Member

    Hi, @roji !

    When I started to implement GetSchema support in 2005 (https://github.com/npgsql/Npgsql1-From-CVS/commit/617081e939b38ba225de19650f5121cc11933e09) , I used a new NpgsqlConnection. I think I choose to create a new connection only to not have problems with the NpgsqlConnection currently in use. So, there was no specific reason for it to be like it is today :)

    I think there wouldn't be any problems using the same connection, and it would fix this issue :)

  5. roji commented on Mar 19, 2015

    @roji
    Member

    OK, thanks @franciscojunior, I'll make the change.

  6. added a commit that references this issue on Mar 19, 2015
    85736b0
  7. roji commented on Mar 19, 2015

    @roji
    Member

    Fixed and backported to 2.2

  8. added theissue type on Jun 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions