Connection String Help

G

Guest

Hello,
I was wondering what the best way would be to dynamically determine and
store connection string information. What I mean by this is that I want the
application to user the servervariable to determine what location it is
running in and then dynamically assign a connection string value based on
that location. I was planning on doing this from the codebehind pages which
works fine because I am able to use the response object to determin where the
code is running but I am not sure what to do in a vb class file where I have
no access to server variables. Any Ideas???


THANKS
 
I

IPGrunt

Hello,
I was wondering what the best way would be to dynamically determine and
store connection string information. What I mean by this is that I want the
application to user the servervariable to determine what location it is
running in and then dynamically assign a connection string value based on
that location. I was planning on doing this from the codebehind pages which
works fine because I am able to use the response object to determin where the
code is running but I am not sure what to do in a vb class file where I have
no access to server variables. Any Ideas???


THANKS

Why don't you have access to the server object through current context? (as
in System.Web.HttpContext.Current.Session)

-- ipgrunt
 
S

Scott Allen

One solution is to use the shared property HttpContext.Current to get
back to the 'context' of the request, i.e. party on
HttpContext.Current.Request.ServerVariables. Just import the correct
namespace (System.Web) and also reference the System.Web assembly if
you are in another project.

The drawback is you won't be able to use the code outside of a web
application. Perhaps this is not a drawback for your design, but just
a thought for consideration.
 
P

Peter Rilling

It might also be good if the connection string was passed into your objects
through the constructor or some method/property. That way the objects to
not know anything about the server and can actually run in environments that
are not running on the server such unit tests.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top