Passing Connection String to Server

Passing Connection String to Server

Old forum URL: forums.lhotka.net/forums/t/376.aspx


Pradeep posted on Wednesday, June 14, 2006

Hi all,
I like to know how the connection string info is passed from client to server when I am using a remote server configuration. Will the app.config get automatically passed to the server?
 
I understand that when we call a fetch method, it moves the whole object to the server and executes the fetch method inside the object. But inside my fetch method I have the line like
 
using(SqlConnection cn = new SqlConnection(DB("PTracker"))).
 
How does my DB method get the configuration from the app.config file which is on the client ?
 
The whole reason for asking this question is this. I do not want to have my connection string in the config file for security reasons. So what I am thinking of doing is,  create a custom Identity object (deriving from IIdentity) and my Identity object will have a parameter called ConnectionString. When ever I want the ConnectionString, I get it from this object.
 
My assumption is that .Net automatically passes the Principal object from client to server. So if I want to get the connection string in the server, it would be available in the Identity object.
 
Please let me know if this will work in distributed architecture. The main thing I am trying to accomplish is to pass in a set of data to the server, that would be used by all my objects.
 
Thank You ...
 
 

kdubious replied on Wednesday, June 14, 2006

You would need to add the connection string to the web.config in the DataPortal.

DavidDilworth replied on Thursday, June 15, 2006

Pradeep:
How does my DB method get the configuration from the app.config file which is on the client ?

To put it bluntly, it doesn't.

In a remoting situation you will have the following:

(1) Client (or web server)
(2) Application server
(3) Database server

The configuration file on the client (or web server) should only have the remoting details for getting to the app server and nothing else.  The client (or web server) cannot communicate with the database server directly, so does not need the connection details!

The configuration file on the app server is the only place where you need the connection details for the database, since the app server is the only box that can communicate with the database server.

HTH

Pradeep replied on Thursday, June 15, 2006

Thanks David.
 
One more question, will the IPrincipal object be passed to the server?

Pradeep replied on Thursday, June 15, 2006

What I mean in above questions is that, if I want to pass in some parameters to the server, can I put that in my IPrincipal derived object and send it to the server.
 
Please let me know.
 
Thank You
Pradeep

guyroch replied on Thursday, June 15, 2006

The IPrincipal is always available on both the client and app server (including when using remoting) when using Csla.ApplicationContext...

However, if you are using the IPrincipal as a mean to transport parameters from the client to the app server and back, then I think you are abusing the fundamental purpose of IPrincipal.

Why aren't you using the Criteria object to do this?

tymberwyld replied on Monday, August 07, 2006

I am working on similar functionality.  In our application we may have users logging into one Database and our QA or Development team logging into a completely different database.  Yet, I want to use the same DataPortal because all it really is doing is relaying the data access.

So, I think I've decided to override the "DataPortalContext" to include Properties: Database, Server, DatabaseType (SqlServer, Oracle, etc.).  The DataPortal or Business Object can then build the connection string dynamically.

Copyright (c) Marimer LLC