locked
Is there a negative to creating a new OracleConnection, but not opening it? RRS feed

  • Question

  • User1864322503 posted

    I have a helper class in an external library which takes in an OracleConnection and returns whether it is a Production, User or Test database.

    Basically I do 

    OracleConnection conn = new OracleConnection(ConfigurationManager.ConnectionStrings["MyConnection"].ConnectionString);

    then

    string environmentName = ApplicationEnvironment.GetEnvironment(conn).ToString();

    Since I am never opening the connection, can anyone confirm that this is not something to be concerned about?

    Tuesday, December 8, 2015 2:17 PM

All replies

  • User753101303 posted

    Hi,

    Shouldn't but as a best practice just dispose the connection once you are done with it as for all disposable classes. Not sure what you are doing but if this is to check its connection string then you likely  don't need anyway to create a connection.

    Tuesday, December 8, 2015 2:31 PM
  • User269602965 posted

    depends on operational tempo and number of users.

    small office app with user requesting a select here, insert there, update this,

    and open and close not a problem

    ramp that up to thousands of users coming at you with all kinds of requests

    then staying open and adding things like connection pooling become more important

    Tuesday, December 8, 2015 10:12 PM