Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
8
Erster Beitrag:
vor 5 Jahren, 2 Monaten
Letzter Beitrag:
vor 5 Jahren, 2 Monaten
Beteiligte Autoren:
Piet van Zanten, Paulo Oliveira, Fabrice Harari

[WD16] Copy database from HFCS to MS SQL Server Express

Startbeitrag von Piet van Zanten am 07.06.2013 09:25

Hi,

I need to copy a HFCS database into MS SQL Server Express 2012.
Is anybody willing and able to share some sample code to duplicate the HyperfileSQL file descriptions and data into the MS SQL database?
Or is there a (free) utility available somewhere to do this?

Regards,
Piet

Antworten:

Code example to copy data from one DB to another.
Probably you will need to complete it.
It doesn't duplicate the structure but hcreation can help you.


IF NOT HOpenAnalysis(analise) THEN
Error("erro ao abrir a analise",ErrorInfo())
ReturnToCapture(analise)
END

// ligar input
// Trata hiperfiles
IF tipo_in="HF" THEN
IF NOT HDescribeConnection("CONN_IN","","",DB_in,"",hAccessHF7,hOReadWrite,"") THEN
EndProgram("Erro no hdescribeconnexion para HF - "+CR+ErrorInfo())
END
END

// Trata sqlserver
IF tipo_in="SQL" THEN
IF NOT HDescribeConnection("CONN_IN",user_in,pass_in,Server_in,DB_in,hNativeAccessSQLServer,hOReadWrite,"WD Connection Timeout = 600; WD Command Timeout=600") THEN
EndProgram("Erro no hdescribeconnexion para SQL - "+CR+ErrorInfo())
END
END
// Trata oracle
IF tipo_in="ORA" THEN
IF NOT HDescribeConnection("CONN_IN",user_in,pass_in,Server_in,DB_in,hNativeAccessOracle,hOReadWrite,"WD Connection Timeout = 300; WD Command Timeout=300") THEN
EndProgram("Erro no hdescribeconnexion para ORACLE - "+CR+ErrorInfo())
END
END
// Trata HF client server
IF tipo_in="HFCS" THEN
IF NOT HDescribeConnection("CONN_IN",user_in,pass_in,Server_in,DB_in,hAccessHFClientServer,hOReadWrite,"WD Connection Timeout = 600; WD Command Timeout=600") THEN
EndProgram("Erro no hdescribeconnexion para HFCS - "+CR+ErrorInfo())
END
END

IF NOT HOpenConnection("CONN_IN") THEN
EndProgram("Erro no HOpenConnection - "+CR+ErrorInfo())
END
IF NOT HChangeConnection("*","CONN_IN") THEN
EndProgram("Erro no HChangeConnection - "+CR+ErrorInfo())
END

// ligar OUTPUT
// Trata hiperfiles
IF tipo_out="HF" THEN
IF NOT HDescribeConnection("CONN_OUT","","",DB_Out,"",hAccessHF7,hOReadWrite,"") THEN
EndProgram("Erro no hdescribeconnexion para HF - "+CR+ErrorInfo())
END
END

// Trata sqlserver
IF tipo_out="SQL" THEN
IF NOT HDescribeConnection("CONN_OUT",user_out,pass_Out,Server_out,DB_Out,hNativeAccessSQLServer,hOReadWrite,"WD Connection Timeout = 600; WD Command Timeout=600") THEN
EndProgram("Erro no hdescribeconnexion para SQL - "+CR+ErrorInfo())
END
END
// Trata oracle
IF tipo_out="ORA" THEN
IF NOT HDescribeConnection("CONN_OUT",user_out,pass_Out,Server_out,DB_Out,hNativeAccessOracle,hOReadWrite,"WD Connection Timeout = 300; WD Command Timeout=300") THEN
EndProgram("Erro no hdescribeconnexion para ORACLE - "+CR+ErrorInfo())
END
END
// Trata HF client server
IF tipo_out="HFCS" THEN
IF NOT HDescribeConnection("CONN_OUT",user_out,pass_Out,Server_out,DB_Out,hAccessHFClientServer,hOReadWrite,"WD Connection Timeout = 600; WD Command Timeout=600") THEN
EndProgram("Erro no hdescribeconnexion para HFCS - "+CR+ErrorInfo())
END
END

IF NOT HOpenConnection("CONN_OUT") THEN
EndProgram("Erro no HOpenConnection - "+CR+ErrorInfo())
END

WOUT is Data Source
wanalise is string
wfile is string
wanalise=HListFile(hLstSorted)
wfile=ExtractString(wanalise,firstRank,CR)
WHILE wfile EOT
Message(wfile)
MultitaskRedraw(Define_connection)
IF NOT HAlias({wfile},WOUT) THEN
EndProgram("Erro no HAlias - "+CR+wfile+CR+ErrorInfo())
END
IF NOT HChangeName(WOUT,wfile) THEN
EndProgram("Erro noHChangeName - "+CR+wfile+CR+ErrorInfo())
END
IF NOT HChangeConnection(WOUT,"CONN_OUT") THEN
EndProgram("Erro no HChangeConnection - "+CR+wfile+CR+ErrorInfo())
END
IF NOT HDeleteAll(WOUT) THEN
EndProgram("Erro no HDeleteAll - "+CR+wfile+CR+ErrorInfo())
END
HReadFirst({wfile})
WHILE NOT HOut()
HCopyRecord(WOUT,{wfile})
IF NOT HAdd(WOUT) THEN
EndProgram("Erro no HAdd - "+CR+wfile+CR+ErrorInfo())
END
HReadNext({wfile})
END
HClose({wfile})
HCancelAlias(WOUT)
HCancelDeclaration(WOUT)
wfile=ExtractString(wanalise,nextRank,CR)
END

HCloseAnalysis()
HCloseConnection("CONN_IN")
HCloseConnection("CONN_OUT")
[attachment 404 screen.JPG]

von Paulo Oliveira - am 07.06.2013 10:00
Hi Paolo,

Many thanks.
I'm not at home right now, so I cannot test it.
Do you know if hCreation will work on an odbc connection?

Best regards,
Piet

von Piet van Zanten - am 07.06.2013 11:34
Hi Piet

you should have a look at the following:

in the analysis, Menu Structure of Files, last option: Generate the SQL script

It should generate the sql script to create the DB with the proper structure

Best regards

von Fabrice Harari - am 07.06.2013 12:13
Hcreation by ODBC doesn't work but it works by OLEDB

http://doc.windev.com/en-US/?3044255

von Paulo Oliveira - am 07.06.2013 13:24
Hi Fabrice,

That would be a great solution!
I'll try it.

Best reagrds,
Piet

von Piet van Zanten - am 07.06.2013 13:59
Hi,

To whom it may concern.
The script generation works fine, you can even select the target SQL type.
The generated SQL script is ok, except that for unknown reasons both date and time types are defined as datetime. This will generate type conversion errors when inserting the records.
One needs to manually change the datetime type to date or time, according to the actual type in Windev.

Regards,
Piet

von Piet van Zanten - am 09.06.2013 10:28
Hi Paolo,

I ended up doing it all with SQL, that worked fine and again I learned a little bit ;)
Thanks for your help.

Best regards,
Piet

von Piet van Zanten - am 09.06.2013 10:32
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.