Skip to content

When trying to change default database it fails because connection is not open #1

Closed
@JamesHorsley

Description

@JamesHorsley

In this below the call to cn.ChangeDatabase fails because the connection is not yet open - it needs moving to after the cn.Open()

try
                {
                    if (!database.Equals("master", StringComparison.InvariantCultureIgnoreCase))
                    {
                        cn.ChangeDatabase(database);
                    }

                    var sqlBatch = string.Empty;
                    var cmd = new SqlCommand(string.Empty, cn);
                    cn.Open();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions