Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
CusorAdapter & ConnectionsStrings
Message
 
To
21/09/2006 06:12:17
Hans-Otto Lochmann
Dr. Lochmann Consulting Gmbh
Frankfurt, Germany
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
01155863
Message ID:
01155867
Views:
33
This message has been marked as the solution to the initial question of the thread.
>Hi All!
>
>My question:
>Is there a way to have a "central place" to store a ConnectionString once, which can then be used in testing CursorAdapters, forms etc., and which can be included in the final application, so it can be loaded at installation time with "the" suitable ConnectionString?
>(See below)
>
>I'm working on a project which finally will run on several installation sites, each with its own SQL Server. The database in the SQL Server will include some 20+ tables. The application will consist of (among others) several forms, each with a DataEnvironment, which will use CursorAdapters to connect to the SQL Databases.
>
>I have set up a class library, which presently has only 10 CAs classes using the CA builder, which is a great help for many details. Each class got a hard coded ConnectionString. I tested the classes in the command window, everything worked fine - I could fetch data, save data, delete records, insert records etc.
>
>I then set up a test form with a DE, which includes some instances of the above CAs. I checked the check box of each instance of each CA, which says that it should "use the DataEnvironment data source", which has been set to the same hard coded ConnectionString. All done, using the appropriate builders.
>
>Testing worked fine, unless I hooked my notebook onto a different SQL server, which naturally requires a different ConnectionString. Who ever tried that, knows what happened: I could neither run the test form nor open its DE without receiving a nasty error message for each CA but only after the timeout had elapsed. In order to get it working I had to change each ConnectionString in each CA class and in the DE to the new setting.
>
>I would like to set up in my testing environment something like
>
>
>*-- Dummy class whose sole purpose is to provide for oApp.MyConnectionString
>Define Class MyApplicationDummyClass As Relation
>MyConnectionString = NULL
>Enddefine
>
>which would allow me to issue something like (before starting to test anything)
>
>Public oApp as object
>oApp = CreateObject("MyApplicationDummyClass")
>oApp.MyConnectionString = "<whatever is needed>"
>
>which then would allow having in the INIT of the CAs and the DEs something like
>
>This.DataSource = SQLStringConnect( (oApp.MyConnectionString) )
>
>which would work when testing as well as when running in the final application. By the way: This works for CAs. But it has to be manually changed in the INIT after using the builder (which could be updated accordingly, see Doug Hennig's Mine for Code in XSource, Prague DevCon 2006).
>
>Before I invest more time, I would like to ask you for your valuable comments and ideas on that topic: Does anybody have any experience with something like this? Or have some better ideas?
>
>Any help appreciated
>
>Hans

If you use ODBC for your CAs, you could use one Connection for all CA. Keep in mind that every connection to SQL Sever slows down application. So you could store your sqlHandler AND connection string everywhere you want. If you didn't have application object that is visible in whole application, you could add these properties to _screen object (_screen is available even if you you a Top-Level form as Main screen). So In your main program you could do:
IF NOT PEMSTATUS(_SCREEN,[cSQLString], 5)
   _screen.AddProperty([cSQLString])
ENDIF

IF NOT PEMSTATUS(_SCREEN,[nSQLHandler], 5)
   _screen.AddProperty([nSQLHandler])
ENDIF

_screen.cSQLString = ??? && Read your string

_screen.nSQLHandler = SQLSTRINGCONNECT(_screen.cSQLString)
*** Check for errors and if you can't connect just quit application

<pre>

Then in all of yours CAs put:
<pre>
this.DataSource = _screen.nSQLHandler
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform