Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing database passwords around 1

Status
Not open for further replies.

RSfromCO

Programmer
Joined
May 3, 2002
Messages
149
Location
US
I am developing a vb.net application that uses an MS-Access database that has a password.

When the application first starts up I ask the user for the password for the database. It uses that password to connect to the database to verify the password provided was correct. All is well.....

Then they open a form, which opens another form, which creates an object, that needs data from the database where eventualy a database connection object needs to be created for that business object. Well, the password for the database is known by the form several layers back....

Is there a better way of getting the database password into the data access object (where it is actually needed) other than passing it around from form to form, object to object, until it is actually used?

This is not a web enabled application, so there is no "session" object to set the password variable on. But basically I think what I need is some sort of "global" object that the entire application can access, so all objects can see what the database password is if they need to.
 
Create a public variable in a module.
 
A problem I am having with this is that my Business Objects (that interface with the database) are being compiled into a seperate DLL called MBO, while the user interface project is where the password is entered by the user.

If I create a Public Module DBconnectionData under the user interface project I can access the variables. However when I try to access the variables from my Business Objects (which are in the namespace called MBO) I can't seem to access them.

If I create the Public Module DBconnectionData inside the MBO dll, I can't seem to access the variables from my user interface project.

Hopefully my description makes sense. Any suggestions?
 
Yes. Don't create the dll so that it HAS to retrieve the variable on its own. If the dll relies on another piece of software to function, then it's not re-useable. Make a method to pass in the connectionstring to the dll.

You can still use the public variable so that you can readily get it from any form in your project that needs to use the dll.
 
How do I pass the connection string to the DLL other than passing it to every object in the dll that is going to need the connection string? I would like to only pass the connection string to the DLL one time or as needed when I know the connection string needs to change.
 
Set it in one place in the dll that is accessible elsewhere from within the dll
 
OK... I think I got it. I created a Module in the DLL and then I created an Object in the DLL that SETs the values in the Module. So, from outside the DLL I can instantiate the object, use it to set the values in the Module. From that point on other objects in the DLL can read the Module public variables.

GREAT !!!!!

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top