Skip to content

NH-3321 - MsSqlDataBaseSchema gets schema for wrong catalog #1289

@nhibernate-bot

Description

@nhibernate-bot

Luke Horsley created an issue — 7th November 2012, 15:25:56:

I am using MS SQL 2005 and have noticed the following.

All of the GetSchema calls inside of MsSqlDataBaseSchema/AbstractDataBaseSchema operate using the default catalog of the DbConnection.

This means if I have a class mapped to a different catalog, the tables used for this class are not returned as part of the GetTables call.

I believe the catalog parameter should be used to change the database being used by the DbConnection.

Perhaps something like:

public virtual DataTable GetTables(string catalog, string schemaPattern, string tableNamePattern, string[] types)
{
    var originalCatalog = Connection.Database;
    try
    {
        Connection.ChangeDatabase(catalog);
        return Connection.GetSchema("Tables", new string[]
        {
            catalog, 
            schemaPattern,
            tableNamePattern
        };
    }
    finally
    {
        Connection.ChangeDatabase(originalCatalog);
    }
}

Oskar Berggren added a comment — 20th November 2016, 19:07:00:

Pull request with tests would be helpful if you can manage.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions