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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deploy Database and connection with the application

Status
Not open for further replies.

Dhagaxtuur

Technical User
Apr 15, 2003
47
0
0
CA
I have program that uses access database. I am using ADO connection to access the database.

The problem is, when I want deploy the application to another computer with different setting (for example if my database rooted to C:/programs files and client computer runs from D: and my program is deployed to D:/program files) then I lost the connection. Is there a way I can make the database connection dynamic so the database can be located anywhere on the computer and still have the connection?

If you have the answer, please give me in details. I was searching answer to this question for while. Thanks
 
How about:

1) You ask your users to set up a network drive of say S:. Then your connection will always be S:\access.mdb. It is then up to the user / installer to specify wherever S points to!
or
2) When your app fires up do a quick check to see if the database exists where you expect it to, if it doesn't then open a dialog box asking the user to locate it.
or
3) the really scary one...
If your database name is unique i.e. that is if you found it you;d know it is yours then try this. Basically check in the directory you expect, then check the current directory..then if still not found traverse eery drive you can "see" and find it! Can be done easily with the drivebox, directorylistbox and filelist controls. Obviously would take the most time and would have to make sure that only one copy of your db existed.


Interestingly I have been trying to find some controls that do ADO connections. Where did you get them from ? What version of C++ Builder are you using ?

Regards

BuilderSpec
 
Well, I've developed only one ADO program but I do distribute it among various networks. There is an undocumented API that I use to set up the ADO. The call is PromptDataSource(). You provide the handle to the calling program and a widestring with a connection setup. The widestring then returns an ADO connection string. For example, I might use it like:
Code:
    AnsiString ADOStr = SQLLabeledEdit->Text;
    WideString WADOStr;
    if (ADOStr.UpperCase() == "UNKOWN")
        WADOStr = "";
    else
        WADOStr = ADOStr;
    WideString WResult = PromptDataSource((int)Application->Handle, WADOStr);
    SQLLabeledEdit->Text = WResult;

In the above example, SQLLabeledEdit holds the original ADO connection string. If the string is Unknown then the string I pass to PromptDataSource() is blank; otherwise, the call uses the string to set up the connection where you can just press the "Test Connection" button to see if it is valid.

The PromptDataSource() is used by many companies to set up their DB calls, I've seen it used in Crystal Reports, etc. If you want to have the call return the password, you must check "Allow Password Saving." If you do this, the password is sent back in cleartext. This is OK unless you need to save the info somewhere for later reuse, i.e., the registry or Ini file. In this case, you should encrypt the string.

Once you have the string you can use it in your ADO component.
Code:
WoodWorkADODataSet->ConnectionString = SQLLabeledEdit->Text;

What I've left out is my encryption codes so SQLLabeledEdit isn't in cleartext. Of course, you can by pass the edit string entirely and just use the ADO's connection string but in my above example, I send the encrypted string to the registry for later recall.

James P. Cottingham
-----------------------------------------
[sup]To determine how long it will take to write and debug a program, take your best estimate, multiply that by two, add one, and convert to the next higher units.[/sup]
 
I am using borland C++ Builder 6 Enterprise. It has an ADO component and database quiries.

2) When your app fires up do a quick check to see if the database exists where you expect it to, if it doesn't then open a dialog box asking the user to locate it.

This sounds good to me but how I check the existant of the database, display diogbox if not exist and use the provided string to connect to the database?

As of 2ffat solution. I am not familiar with these component PromptDataSource/SQLLabeledEdit and the code you have provided but I will look into it.
 
One thing I forgot to mention, SQLLabeledEdit is really a LabeledEdit component, just like WoodWorkADODataSet is really an ADODataSet. Sorry if this caused any confusion.

James P. Cottingham
-----------------------------------------
[sup]To determine how long it will take to write and debug a program, take your best estimate, multiply that by two, add one, and convert to the next higher units.[/sup]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top