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

Using Code to Bind Data Enviroment 1

Status
Not open for further replies.

x508

Programmer
Jun 26, 2003
396
0
0
ZA
Hi all

Is it at all possible to use code to build my data enviroment at runtime.

The problem I find is that it works quite well if you use the propperty pages of the dataneviroment to get the database location and connection string and so-on.

But I'm faced with the problem that when my application will be distributed, the database path will not be the same any-more. For instance, my App was developed in "F:\Stock". When it will be installed, the user is surely able to specify where he would like it to be installed, ie. "C:\Program Files\Stock"

Can anybody please help me with some suggestions?

Thanks is Advance

X50-8
 
One way to solve this is to copy the connectionstring into the code and where it states the path

(Data Source=f:\stock\databesename.mdb;...)

replace it with

Data Source=" & APP.PATH & "\databasename.mdb;...)

then you have to delete the connectionstring in the property's

Normally that would solve your problem.

Peaple that try to make something that is completely foolproof underestimate the genius of real fools.
 
nickske...

Thanks for your input, and it makes sense...

Please just can you explain to me in baby steps, how I should do this. I know all about App.Path and so forth, I just do not know where in the code to use your advice (Which Code? , dataenviroment_initialise, normal code, command_initialise?)

The data enviroment also does not have a connection string that I can find, although the command object does. Still i can not get my code to assign a new value to the data source field of that command object. My VB doe not automatically pop up the option for datasource on that object.

Thanks in advance again

x50-8
 
its like this
suppose ur connection object was conn
then u'd say
conn.connectionstring = "......
"datasource = f:\stock\hello.mdb"

now u shld say
"datasource = " & app.path & "\hello.mdb"

 
Anantrai, tnx for your input, bt it seems as if you did not really read my reply to Nickske, please read it again...

Thanks

x50-8
 
you need to write it in the connection1_willconnect event and dataenvironment1_intialize event.

open the dataenvironment window and select the connection1 and open the properties window and in it we find the connectionsource. copy it and paste it in teh connection_willconnect event and make the appropriate changes

i'll give you an example

Private Sub Connection1_WillConnect(ConnectionString As String, UserID As String, Password As String, Options As Long, adStatus As adodb.EventStatusEnum, ByVal pConnection As adodb.Connection)

Connection1.ConnectionString = "Driver={Microsoft ODBC for Oracle};server=" & oracleserver & ";Uid=" & oracleuid & ";Pwd=" & oraclepwd & ""

End Sub


or it can be like

Private Sub Connection1_WillConnect(ConnectionString As String, UserID As String, Password As String, Options As Long, adStatus As adodb.EventStatusEnum, ByVal pConnection As adodb.Connection)

Connection1.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=mydsn"

End Sub


whatever you copy, paste into the connectionstring and then make the changes.
 
Ahhhhhhhhhhhhhhhh....teresachristy

I thanks thee, at last it makes a whole lot more sense.

Thanks

x50-8
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top