Efficient Connection Creation for Data Access

In the generated code: File DataAccess.cs --> Class SqlStatement.
The constructor of teh class looksup the connection string and the DbConnectionFactory before creating the connection.

Since it is highly unlikely that applications deployed to production add/change database settings without an application restart, it will be more efficient to add a static constructor to SqlStatement class that reads all connection string, creates DbConnectionFactories and caches them in static variables.

Then when the need arises, the CreateConnection() method can be called on a cached DbConnectionFactory, saving on a couple of method calls for each DB activity
1 person likes
this idea
+1
Reply
  • Sudhanshu, the time required to instantiate the connection string is infinity small compared to the time the request is traveling between the client browser and computer, or the time required to render HTML in a browser.

    It is very likely that data provider factories are cached by .NET Framework.

    You can always override CreateConnection method of the partial Controller class if you feel that application performance is significantly improved that way.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited indifferent, undecided, unconcerned kidding, amused, unsure, silly sad, anxious, confused, frustrated