Diese Seite mit anderen teilen ...

Informationen zum Thema:
WinDev Forum
Beiträge im Thema:
Erster Beitrag:
vor 2 Jahren, 4 Monaten
Letzter Beitrag:
vor 2 Jahren, 3 Monaten
Beteiligte Autoren:
Al, GuenterP, Piet van Zanten, Steven Sitas

WD[20] Do I have to use HConnection everytime I use an Alias ?

Startbeitrag von Al am 18.02.2016 06:09

Hello All

In a previous post I highlighted a problem using Halias() that only occurs in HFCS and not in HFClassic. A suggested solution was to use HChangeConnection but that didn't fix the problem and after reading the help I am quite confused about the correct method of using HAlias() in HFCS

From the Help:
If HChangeDir or HConnect has been used with the initial file, these changes are ignored by the file.
Once an alias was created, we recommend that you use HConnect to define the connection parameters on the alias file.

I run a single HConnection() to the HFCS in the project init code. I have a large number of HAlias() calls in the app and they all appear to work except in the case where the files is aliased as a source back to itself and I can appreciate that may cause issues.

My questions are:
Do I have to use HChangeConnection(AliasFileName,HFCSConnectionName) in every case after declaring the alias and before the HCHangeName() ?

If this is the case do I have to test for running in HFCS or Classic before issuing the HChangeConnection(AliasFileName,HFCSConnectionName) or will Windev ignore it if I am running with an HFClassic database ?

Should I follow the help and use HConnect() which doesn't seem the way to go as I will be constantly making and breaking connections ?



Hi Al, whenever you're opening an Alias file (e.g. CUSTOMER1) then in fact it is meant to point to the aliased file (e.g. CUSTOMER) in the HFCS database. In order to connect the alias file (CUSTOMER1) of the client computer to the original file (CUSTOMER) in the server-based datafile, you have to "connect" them, there's no way out. This is what HOpenConnection(...) does - after all, for the HFCS database it is a new file connection with a new file pointer. You can circumvent this nuisance simply by using queries to CUSTOMER, as far as I my experience goes, queries to the original file don't disturb the file pointer of the H-commands. Moving to the next CUSTOMER record by HReadNext(..) will be possible though some queries have been executed before. If you fear (or experience) that your file pointer is / could be disturbed by any queries, just save the file pointer by HSavePosition(..) and restore it by HRestorePosition(..). HTH

von GuenterP - am 18.02.2016 06:45
Hello Guenter

Thanks for the reply. I still have a couple of questions though.
Can I run the same code for HFClassic ?
If I am not using HFCS in an installation, does Windev ignore the HChangeCOnnection() commands ?
I have three separate pieces of advice now to solve the issue
The Help says to use HConnect
Steven reccommends HCHangeConnection
You reccommend HOpenConnection
And I have no reason to doubt any of the prposed solutions.

On top of all that, in some instances it appears to be working without doing anything and there is PCSoft's claim that the only thing you have to do to switch from Classic to HFCS is to convert the files by importing them into a HFCS database.

I have 527 HAlias() assignments in one of my apps that I have to rework somehow.


von Al - am 18.02.2016 09:12
Hi Al,
HF C/S and Classic do have some differences and code is NOT always 100% compatible ...
I am quite sure that HChangeConnection() will do the job and thats what Guenter is really saying. HOpenConnection() does the initialising at the BEGINNING of your app and uses your analysis BUT you will have to use HChangeConnection() to ADD NEW FILES to your ALREADY opened Connection - these would be your Alias files ..

I always have a global variable that shows what type of files I have (Classic, C/S, MySQL etc ) so I can change the code I use in my app (with a simple IF ..)

The last couple of years I have changed ALL my code that uses H* functions (like HAlias, HSavePosition etc) to Queries and the ONLY one I use is HFReadSeekfirst() on the primary key.
This didn't affect the "speed" of my apps and I am quite sure that my code will now work 100% between databases.

Steven Sitas

von Steven Sitas - am 18.02.2016 09:52
Hello Steven

Thanks for the followup.
I did try the HCHangeConnection() but it didn't work in the case I tried it on which was using the same file for a source file to read from and also as a repository for HCopyRecord() between the two so maybe that's a unique case. I will try it on some of the other uses of HAlias().

Given the fact that I may have to also start excluding code based on wether I am using HF Classic or HFCS I am more inclined to just get rid of all the HAlias constructions and replace it with views as it will be quicker than building queries.


von Al - am 18.02.2016 10:18
Hi Al, I'm sorry I had to leave the office ... I'd say that you can have a comparable behaviour of C/S and Classic when using HOpenConnection with the database files.

For HFCS it looks like

// Connection to HFCSDatabase
MyConnection..User = NoSpace(MyHFCSAdminName)
MyConnection..Password = NoSpace(MyHFCSAdminPassword)
MyConnection..Database = NoSpace(MyDatabaseName)
MyConnection..Server = MyServerAndPort
MyConnection..Provider = hAccessHFClientServer
MyConnection..Access = hOReadWrite
MyConnection..CursorOptions = hServerCursor+hDynamicCursor+hOptimisticCursor
MyConnection..ExtendedInfo = ""
MyConnection..CryptMethod = hCryptStandard

IF NOT HOpenConnection(MyConnection) THEN
Error("HFSQL: HOpenConnection: ","Die Verbindung zu "+MyServerAndPort + " kann nicht errichtet werden !",HErrorInfo(hErrFullDetails))

MyConnectionName = MyConnection..Name

//Info("Connection "+MyConnectionName+" established successfully !","Database "+MyConnection..Database+" found / generated !")

// Die Verbindung aller Dateien einrichten:
// Fehler aufgetaucht:
EndProgram("HFSQL: Fehler bei HChangeConnection aufgetreten !",HErrorInfo(hErrFullDetails))

and for Classic it's

// Make connection to Data
MyConnection..User = "Admin"
MyConnection..Password = ""
MyConnection..Database = ""
MyConnection..Server = ""
MyConnection..Provider = hAccessHF7
MyConnection..Access = hOReadWrite
MyConnection..CursorOptions = hServerCursor+hDynamicCursor+hOptimisticCursor
MyConnection..ExtendedInfo = ""
MyConnection..CryptMethod = hCryptStandard
MyConnection..Source = NoSpace(MyPathToHFClassic)

IF NOT HOpenConnection(MyConnection) THEN
Error("HF Classic: HOpenConnection: ","Unable to connect to HF Classic-Dir: "+MyPathToHFClassic,HErrorInfo(hErrComplet))

There shouldn't be too much difference between both of them

von GuenterP - am 18.02.2016 17:26
Hello Guenter

Thanks for the example.
I assume the reason behind establishing a fake connection to the HFClassic database in the init is to allow the HChangeconnection to work in all cases without having to test which type of database I am accessing. That will make the changes I have to do a lot quicker.


von Al - am 18.02.2016 19:52
Hi Al,

If you do need to change code you might consider simplifying it.
Two simple options that Guenter already pointed out, no need for hAlias:
1. Loop through the file, do hSavePosition, save the filebuffer to a new record using hAdd (no hCopyFile needed) do hRestorePosition.
2. Create a query, loop through the query and save the record using hCopyRecord and hAdd directly to the file.


von Piet van Zanten - am 19.02.2016 10:59
Hello Piet

Thanks for the suggestion, I am using a variety of the suggestions made in the threads.
I suppose the real problem for me is that there is no clear statement from PCSoft anywhere in the help that lists the issues that may arise in the conversion from Classic to CS and now that one has surfaced I wonder if there are any more ?


von Al - am 20.02.2016 00:35
Hello All

Thanks to everyone for posting on this thread and the earlier one.
The solution I used was to go with Guenters idea of a second connection to HFClassic which then meant that I didn't have to test which backend I was using and I could just issue HChangeConnection() as required because I always had a defined connection.

The mistake I made when implementing Steven's orignal suggestion re HChangeConnection() was to not also include a HChangeName() command because I thought it wasn't required if I used HChangeConnection() - even though it was in his original suggestion :)

It leads me to one final question, which in my mind shows an inconsistency in PCSoft's approach to dynamic file management:

If the premise behind the need for HChangeConnection() is that a "new" file has been created so the system needs to know about it, why don't I also need to issue HChangeConnection() and HChangename() for Views and Queries created dynaically during program execution ?


von Al - am 21.02.2016 07:45
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.