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

Change ConnectionString

Status
Not open for further replies.

miho1

Technical User
Oct 22, 2002
78
BG
Hi All

At me eat Data Environment and I want during performance of the program,
changed ConnectionString. Who that knows as it to make?

I shall be very grateful to all.


Miho
 
I think he's using a DataEnvironment (I've never used them), and wants to change it's connection string at runtime to point to another database. Like I said, I don't use them, but I think you need to close the DataEnvironment and open it again.

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
Hi,

I presume that you are wishing to change the connection string at runtime, so that you can access different datasets depending on some user / program generated activity. Given that this is the case, try the following:

In Data Environment Designer View,

*** Set up data environment DE
*** Set up Connection CN
I used a data source name called "Demo Data". Note that I also have a valid data source name called "Live Data" that points to a different physical data set. My data is accessed via a third party ODBC driver.
*** Set up Command CMD (sql command)

Then in code you can ...

Code:
    Dim x As String
    x = DE.CN.ConnectionString
    
    DE.CN.Open
    DE.rsCMD.Open
    DE.rsCMD.MoveFirst
    Debug.Print DE.rsCMD.Fields(1).Value
    DE.rsCMD.Close
        
    DE.CN.Close
    DE.CN.ConnectionString = Replace(x, "Demo Data", "Live Data")
    DE.CN.Open
    DE.rsCMD.Open "valid SQL command", DE.CN
    
    DE.rsCMD.MoveFirst
    Debug.Print DE.rsCMD.Fields(1).Value

The Debug.Print will give you the first field from the first record in the same data file from the two different data sets.

The Replace command for the connection string may need to be modified slightly depending on the way you connect to your data source. Have a look at DE.CN.ConnectionString to see how this is put together - should give you clue as to how to change it to get the correct result.

Hope this helps ...
 
Thanks PS42

I am glad to see it.
I try all variants and I hope success
Honey agarics of thank.

Miho
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top