Data Environment at run-time (VB 6)
I'm wondering, how to set Data Environment at run-time for using different SQL Server databases in VB 6 data reports, I mean on different servers.
Kaj Bredenberg
Web Development
I'm wondering, how to set Data Environment at run-time for using different SQL Server databases in VB 6 data reports, I mean on different servers.
Kaj Bredenberg
by shanghai sam
You have an opportunity to programatically change the ConnectionString property of the DE using the cnX_WillConnect(...) event of the connection object you configured during development (with a development server/db say). E.g.:
>>> (excuse the linewraps)
Private Sub cnX_WillConnect(ConnectionString As String, UserID As String, Password As String, Options As Long, adStatus As ADODB.EventStatusEnum, ByVal pConnection As ADODB.Connection)
pConnection.Properties("Data Source") = modParams_CN.SQL_DataSource
pConnection.Properties("Initial Catalog") = modParams_CN.SQL_InitialCatalog
ConnectionString = pConnection.ConnectionString
End Sub
<<<
modParams_CN is a module file that has Get/Let properties that can be set prior to instantiating the DE connections (so that on start up the DE will find the right values). I done something similiar get the DE to startup using command objects that are run with different parameters.
A general approach (using the VB DataReport) is:
- deva DE using specific server
- design a report
- code the _WillConnect event to get settings from a seperate module that exposes its properties publicly
- create a class to assess everything including properties and expose those to a calling process.
- build a .DLL and reference it in bigger project
- create an instance of your class, configure the db server you want via the properties.
- call a method that runs your report, etc (which then do the cause the first instance of your DE).
The problem with this approach I find is that the DE can not be easily restarted (w/o weird bugs); you'll have to destroy and recreate an instance of your class; as long as your DE doesn't change, you can leverage any number of class methods to executeagainst it (diff. DataReports, etc).
H
This discussion is closed to new replies.
Sort by Trending