Forum Moderators: open

Message Too Old, No Replies

Where to put connection string

When using COM

         

aspdaddy

12:56 pm on Oct 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



When writing components for ASP sites it makes good sense to always pass the connection string to the authentication component so that they can be re-used on any site/database.

But once inside the app, should every single call to a business component pass a connection string? like this .
objCustomer.Update("Joe Bloggs", 2,2,3, strConn)

It seems a bit strange to do it this way as the business componets are usually specific to 1 app, and so at most have 3 databases - test/staging/live. But an easy way is needed to switch without recompiling.

COM encourages writing stateless components so where should the connection be stored and when should it be set.

duckhunter

9:40 pm on Oct 24, 2004 (gmt 0)

10+ Year Member



Generally with COM, I like to retrieve the connection string and set the value in a local class level variable at time of Object Creation. Then any connection object used in the class can retrieve it from memory whenever it needs it. Alternatively, with multiple classes, it could be stored in a global var as well.

As for where to store it, an encrypted string in an INI file then decrypting it on the fly works well. You can also use the registry to store it but one would prefer access to the registry be restricted.