Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The ado.net context is not able to properly read a connection string from the config file #536

Closed
johelvisguzman opened this issue Jul 17, 2019 · 0 comments · Fixed by #541
Labels
bug Something isn't working
Milestone

Comments

@johelvisguzman
Copy link
Owner

johelvisguzman commented Jul 17, 2019

The ado.net context assumes that the connection string passed in can be found in the app.config, however; this is not a how it should work.

This method is not working!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
This will return an invalid connection string settings in some cases. Needs to investigate...

private static ConnectionStringSettings GetConnectionStringSettings(string nameOrConnectionString)
{
    var css = ConfigurationManager.ConnectionStrings[nameOrConnectionString];

    if (css == null)
    {
        for (var i = 0; i < ConfigurationManager.ConnectionStrings.Count; i++)
        {
            css = ConfigurationManager.ConnectionStrings[i];

            if (css.ConnectionString.Equals(nameOrConnectionString))
                break;
        }
    }

    if (css == null)
        throw new ArgumentException("The connection string does not exist in your configuration file.");

    return css;
}

Maybe do this

private static ConnectionStringSettings GetConnectionStringSettings(string nameOrConnectionString)
{
    var css = ConfigurationManager.ConnectionStrings[nameOrConnectionString];

    if (css == null)
    {
        for (var i = 0; i < ConfigurationManager.ConnectionStrings.Count; i++)
        {
            css = ConfigurationManager.ConnectionStrings[i];

            if (css.ConnectionString.Equals(nameOrConnectionString))
                return css;
        }
    }

    return css;
}
public AdoNetRepositoryContext
{
...
    var css = GetConnectionStringSettings(nameOrConnectionString);
    var connectionString = css != null
         ? css.ConnectionString
         : nameOrConnectionString;
...
}
@johelvisguzman johelvisguzman added the bug Something isn't working label Jul 17, 2019
@johelvisguzman johelvisguzman added this to the 2.9.0 milestone Jul 17, 2019
@johelvisguzman johelvisguzman changed the title The ado.net connection settings is not working as expected The ado.net context is not able to read a provider from a raw connection string Jul 18, 2019
@johelvisguzman johelvisguzman changed the title The ado.net context is not able to read a provider from a raw connection string The ado.net context is not able to read raw connection string Jul 18, 2019
@johelvisguzman johelvisguzman changed the title The ado.net context is not able to read raw connection string The ado.net context is not able to properly read a connection string from the config file Aug 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
1 participant