Seite 1 von 2

MICROSOFT SQL and DBF using at the same time

Verfasst: Sa, 25. Nov 2017 11:38
von engindenizoglu
]How can I open the DBF file and the SQL databank at the same time ?
I can open the SQL datas with xbase 2.0 ; it works fine ;
but when I open a dbf file at the same time I get an error.[/b]


Sample below:
---------------------------------------------------------------------------------

Code: Alles auswählen

   /* Connect using the ODBC driver:DRIVER to
    * the server:SERVER and the database:DATABASE
    * using the given uid:username and pwd:password.
    */
   cConnect := "DBE=ODBCDBE;DRIVER=SQL Server;"
   cConnect += "SERVER=ALCEPROJECT;DATABASE=TestDB;UID=TestUser;PWD=1P_73kny!!;"
   oSession := DacSession():New( cConnect )

   // Test for connection success
   IF .NOT. oSession:isConnected()
     ?"Error code :", oSession:getLastError()
     ?"Description:", oSession:getLastMessage()
     MSGBOX("SORUN VAR")
     RETURN
   ELSE
    * MSGBOX("Connection to server established.","OK - I'm in.")
   ENDIF

SELECT 9
WERNER="SELECT TOP 1000   MOULDTYPE,ORDERNO,ORDERITEMNO,CUSTOMERNO,STOCKCODE,PRODUCTGROUP,OPENTOTAL,CURRENCY,QUANTITY,OPENQUANTITY FROM   ACIK_SATISSIPARISLERI;"    
  BROWSE()                                      /*                sql DATAS can be opened ; everything works fine till here  */

    SELECT 10                          
    USE STO1 EXCLUSIVE NEW          /*   HERE I try to open STO1.DBF  --->  I get ERROR !!!   */
    IF NETERR()=.T.
      CLOSE ALL
     RETURN
    ENDIF

    BROWSE()
---------------------------------------------------------------------------------------------------------




Best Regards
Engin René D.

Re: MICROSOFT SQL and DBF using at the same time

Verfasst: Sa, 25. Nov 2017 11:45
von Jan
Hi,

what error do you get? Can you post the errorlog?

Jan

Re: MICROSOFT SQL and DBF using at the same time

Verfasst: Sa, 25. Nov 2017 12:23
von Martin Altmann
Engin René,
you have to build all dbe you want to use at programstart and should add the VIA-clause to your USE-command to identify the dbe to be used.

HTH,
Martin

Re: MICROSOFT SQL and DBF using at the same time

Verfasst: Sa, 25. Nov 2017 17:33
von engindenizoglu
The error is:
FILE CANNOT BE OPENED.
OPERATION:DbuseArea
Thread ID:1
[42S02][208][Microsoft][ODBC SQL Server Driver]
Invalid Object name 'SUPER'.
Called from MAIN[107]
SUPER.DBF cannot be opened ; Actually this database is in the same directory where the EXE is working.

I first connected to the SQL server (by a DAC ession) and opened some docs (which work fine) and during the session i want to open super.dbf which is located in my own directory.

I started new with xbase 2.0 that's why i don't have too much experience.

Re: MICROSOFT SQL and DBF using at the same time

Verfasst: Sa, 25. Nov 2017 18:06
von HaPe
Your errormessage told me Xbase++ tried to open a DBF with the ODBCDBE-database-driver.

Try now, like Martin suggest:
In Your DBESYS:

Code: Alles auswählen

IF !DbeLoad( 'DBFDBE', .F. )
	Alert( 'Not able to load database-engine DBFDBE' , {'OK'} )
ENDIF
IF !DbeLoad( ODBCDBE', .F. )
	Alert( 'Not able to load database-engine ODBCDBE' , {'OK'} )
ENDIF
Then in your programm:

Code: Alles auswählen

USE STO1 VIA DBFDBE EXCLUSIVE NEW

Re: MICROSOFT SQL and DBF using at the same time

Verfasst: Sa, 25. Nov 2017 20:03
von engindenizoglu
It works:)

The issue is solved.

Now i have another problem ; during append blank to .dbf file i get error message.

---> select 9 --> SQL DATABANK

---> select 7 ---> is a normal DBF file (in my directory)
During 'append blank' to dbf file this error message arises.
Error messag:
Error Base/8021
Unkown Invalid symbol for alias
Operation: Dbappend
Thread:1

------------------------------------------------------------------------------------------------------

Code: Alles auswählen

    SELECT 9      /*   SQL -  werner.dbf   */
    GO TOP
  
    DO WHILE .NOT. EOF()

       SELECT 7         /*  zafer.dbf - DBFDBE  */

      APPEND BLANK                          ---->  Here the error message is given !!!!!
      IF NETERR()=.F.
          REPLACE IKI WITH 9->MOULDTYPE
         REPLACE UC WITH 9->ORDERNO
      ENDIF

      SELECT 9         /*    SQL DATABANK      */
      SKIP


    ENDDO


    SELECT 7
    BROWSE()
----------------------------------------------------------------------------------------------------------

SQLEXPRESS für XBASE++

Verfasst: Mo, 27. Nov 2017 20:53
von engindenizoglu
Ist SQLEXPRESS library für XBASE++ besser geeignet anstelle es mit ODBCE zu benutzen ?

Ist es empfehlenswert SQLEXPRESS XBASE++ library lizenz zu kaufen ?

Wir haben Microsoft SQL SERVER in unserem Betrieb ; ich will SQL Daten und DBF Daten (DBFNTX) mit XBASE++ gleichzeitig programmieren.

Re: MICROSOFT SQL and DBF using at the same time

Verfasst: Mo, 27. Nov 2017 20:55
von georg
Hello,


from my point of view SQLExpress is the better product (you might get different answers). The enterprise version comes with the source code so you are able to adapt (if needed) or recompile (if Xbase++ version changes).

Re: MICROSOFT SQL and DBF using at the same time

Verfasst: Mo, 27. Nov 2017 22:23
von engindenizoglu
During append blank i get error messase . How can i load at program start DBF and SQL DRIVER at the same time ?

------------------------------------------------------------------------------
ERROR LOG of "C:\ALASKA2\00-TRIALS\SQL-X02\SQL-X02.exe" Date: 11/28/2017 00:21:38

Xbase++ version : Xbase++ (R) Version 2.00.853
Operating system : Windows 10 1607 Build 14393
------------------------------------------------------------------------------
oError:args :
oError:canDefault : Y
oError:canRetry : Y
oError:canSubstitute: N
oError:cargo : NIL
oError:description : Unknown/Invalid symbol for alias
oError:filename :
oError:genCode : 66
oError:operation : DbAppend
oError:osCode : 0
oError:severity : 2
oError:subCode : 8021
oError:subSystem : BASE
oError:thread : 1
oError:tries : 1
------------------------------------------------------------------------------


------------------------------------------------------------------------------------------------------------------------------
cConnect := "DBE=ODBCDBE;DRIVER=SQL Server;"
cConnect += "SERVER=ALCEPROJECT;DATABASE=TestDB;UID=TestUser;PWD=KISSROCKS;"
oSession := DacSession():New( cConnect )

// Test for connection success
IF .NOT. oSession:isConnected()
?"Error code :", oSession:getLastError()
?"Description:", oSession:getLastMessage()
MSGBOX("SORUN VAR - We have a connection Problem !")
RETURN
ELSE
MSGBOX("Connection to server established.","OK - I'm in.")
ENDIF

WERNER="SELECT * FROM ACIK_SATISSIPARISLERI WHERE CURRENCY='TRY';"

SELECT 9
USE (WERNER) /* SQL DATABANK */
Browse()

*********************
SELECT 7
USE ZAFER VIA DBFDBE EXCLUSIVE NEW
IF NETERR()=.T.
CLOSE ALL
MSGBOX("COULDNT OPENED !")
RETURN
ENDIF
**********************

SELECT 9 /* SQL - DATABANK */
GO TOP


DO WHILE .NOT. EOF()

SELECT 9

SELECT 7 /* zafer.dbf - DBFDBE */
APPEND BLANK /* HERE I GET PROGRAM ERROR - whY ?

IF NETERR()=.F.
REPLACE 7->IKI WITH HAL1
REPLACE 7->UC WITH HAL2
DBUNLOCK()
ENDIF

EXIT

SELECT 9 /* SQL DATABANK */
SKIP

ENDDO

Re: MICROSOFT SQL and DBF using at the same time

Verfasst: Di, 28. Nov 2017 0:59
von AUGE_OHR
engindenizoglu hat geschrieben: Mo, 27. Nov 2017 22:23 SELECT 7 /* zafer.dbf - DBFDBE */
APPEND BLANK /* HERE I GET PROGRAM ERROR - whY ?
try

Code: Alles auswählen

SELECT 8
or better

Code: Alles auswählen

SELECT (ZAFER)
:-)

btw. you can check it with

Code: Alles auswählen

   aList := WorkSpaceList()

Re: MICROSOFT SQL and DBF using at the same time

Verfasst: Di, 28. Nov 2017 6:18
von Martin Altmann
Gün aydın Engin,
what Jimmy wants to tell with the following sentence:
AUGE_OHR hat geschrieben:try

Code: Alles auswählen

SELECT 8
is simple: You are using the statement NEW together with your USE command - this will select the next free workarea to open the dbf in!
You selected workarea 7 before opening the dbf - by using NEW it will most likely be opened within the next free workarea, which might be number 8.
Simply strip NEW or forget about your SELECT 7 and use the alias-approach when using Db-commands:

Code: Alles auswählen

zafer->(DbAppend(1))
if .not. NETERR()
	zafer->IKI := HAL1
	zafer->UC := HAL2
	zafer->(DbUnlock())
endif
The parameter 1 within the call to DbAppend does not mean to add one record but to keep existing record locks!

Saygılarımla ve iyi şanslar,
Martin

Re: MICROSOFT SQL and DBF using at the same time

Verfasst: Di, 28. Nov 2017 10:51
von engindenizoglu
Thank you , it works.
I'm new in SQL-XBASE writing ; i do write programs since 1991 in clipper afterwards XBASE 1.80 and recently upgraded to XBASE.2.0.

I have another issue now;
field from SQL DATABANK --> SIPARISOLUSTURMATARIHI --> During replacing this field to a DBF file i get the error below.
Maybe the fieldname is too long ; i dont' know. How can i solve problems like these ?


----------------------------------------------------------------------------------------------------------
/* SQL DATA BANK */

Code: Alles auswählen

 WERNER="SELECT TOP 100 SIPARISOLUSTURMATARIHI,MOULDTYPE,ORDERNO,ORDERITEMNO,CUSTOMERNO,STOCKCODE,PRODUCTGROUP,OPENTOTAL,TOTAL,CURRENCY,QUANTITY,OPENQUANTITY,SALESENGINEER,DELIVERY_YEAR,DELIVERY_MONTH,DELIVERY_DAY FROM ACIK_SATISSIPARISLERI;"     /

USE (WERNER) VIA ODBCDBE        /*    OPEN ORDERS  */

    **********  DBF CREATE  ************
    aDbf:={}
    AADD(aDbf, { "BES","C",10,0 })     
    AADD(aDbf, { "ALTI","C",40,0  })   
    AADD(aDbf, { "YEDI","C",15,0  })   
    AADD(aDbf, { "SEKIZ","C",5,0  })   
    AADD(aDbf, { "DOKUZ","C",20,0  })   
    AADD(aDbf, { "ON9","N",15,0  })     
    DBCREATE("ZAFER",aDbf, "DBFDBE")
    ****************************************

    ZAFER="ZAFER VIA DBFDBE EXCLUSIVE NEW"
    *********************
    SELECT 7
    USE ZAFER VIA DBFDBE EXCLUSIVE NEW
    IF NETERR()=.T.
      CLOSE ALL
      MSGBOX("DBF not openedI !")
      RETURN
    ENDIF
    **********************

    SELECT 9      /*   SQL -  werner.dbf   */
    GO TOP

    DO WHILE .NOT. EOF()

      SELECT 9
  
      SELECT (ZAFER)         /*   zafer.dbf - DBFDBE   */
      APPEND BLANK

      IF NETERR()=.F.
   
          REPLACE ZAFER->BES WITH SUBSTR(9->CUSTOMERNO,1,7)    
          REPLACE ZAFER->ALTI WITH SUBSTR(9->CUSTOMERNO,8,30) 
          REPLACE ZAFER->YEDI WITH 9->STOCKCODE

          REPLACE ZAFER->SEKIZ WITH SUBSTR(9->PRODUCTGROUP,1,5)  
          REPLACE ZAFER->DOKUZ WITH SUBSTR(9->PRODUCTGROUP,6,20) 

          REPLACE ZAFER->ON9 WITH 9->(SIPARISOLUSTURMATARIHI)                                    ---> [b]HERE I GET THE ERROR !!!![/b]
     
          DBUNLOCK()
      ENDIF


      SELECT 9         /*    SQL DATABANK      */
      SKIP


    ENDDO
----------------------------------------------------------------------------------------------------------


------------------------------------------------------------------------------
ERROR LOG of "C:\ALASKA2\00-TRIALS\SQL-X02\SQL-X02.exe" Date: 11/28/2017 12:38:04

Xbase++ version : Xbase++ (R) Version 2.00.853
Operating system : Windows 10 1607 Build 14393
------------------------------------------------------------------------------
oError:args :
oError:canDefault : N
oError:canRetry : N
oError:canSubstitute: N
oError:cargo : {NIL, -1, [00000][0][Alaska Software][ODBCDBE]Operation failed.}
oError:description : Error while reading a file
oError:filename :
oError:genCode : 73
oError:operation : SIPARISOLUSTURMATARIHI
oError:osCode : 0
oError:severity : 2
oError:subCode : 8037
oError:subSystem : BASE
oError:thread : 1
oError:tries : 0
------------------------------------------------------------------------------
CALLSTACK:
------------------------------------------------------------------------------
Called from MAIN(230)

Re: MICROSOFT SQL and DBF using at the same time

Verfasst: Di, 28. Nov 2017 10:58
von Martin Altmann
Engin,
why do you put the fieldname in brackets? There is no function like substr() involved, therefore just get rid of the brackets in the corresponding line and it should work.

Çok selamlar,
Martin

Re: MICROSOFT SQL and DBF using at the same time

Verfasst: Di, 28. Nov 2017 12:15
von Koverhage
Ich würde sagen es liegt an dem Alias 9->
Sind die erlaubt ?
An den Klammern liegt es nicht. Das kann man machen (habe ich selbst lange Zeit gemacht)
verlangsamt das Ganze aber.

Re: MICROSOFT SQL and DBF using at the same time

Verfasst: Di, 28. Nov 2017 12:36
von engindenizoglu
It's not related with the brackets.

With or without i always get the same error.

Even i write:

@10,0 say 9->SIPARISOLUSTURMATARIHI ---> again i get an error like the same ; like there is no such a variable field

Re: MICROSOFT SQL and DBF using at the same time

Verfasst: Di, 28. Nov 2017 12:40
von engindenizoglu
WERNER="SELECT TOP 100 SIPARISOLUSTURMATARIHI,MOULDTYPE,ORDERNO,ORDERITEMNO,CUSTOMERNO,STOCKCODE,PRODUCTGROUP,OPENTOTAL,TOTAL,CURRENCY,QUANTITY,OPENQUANTITY,SALESENGINEER,DELIVERY_YEAR,DELIVERY_MONTH,DELIVERY_DAY FROM ACIK_SATISSIPARISLERI;" /

USE (WERNER) VIA ODBCDBE /* OPEN ORDERS */

Or if i would the this field SIPARISOLUSTURMATARIHI at the end the open line ; afterwards i get an error like it's unknown field.
It seems like when the line is too long; problems are arising.


like below;
WERNER="SELECT TOP 100 MOULDTYPE,ORDERNO,ORDERITEMNO,CUSTOMERNO,STOCKCODE,PRODUCTGROUP,OPENTOTAL,TOTAL,CURRENCY,QUANTITY,OPENQUANTITY,SALESENGINEER,DELIVERY,SIPARISOLUSTURMATARIHI_YEAR,DELIVERY_MONTH,DELIVERY_DAY FROM ACIK_SATISSIPARISLERI;" /

Re: MICROSOFT SQL and DBF using at the same time

Verfasst: Di, 28. Nov 2017 12:42
von HaPe
When you do a browse of the sql-server-table do you see in the browse-header this long fieldname?
Which name shows
? FieldName( npos of the long fieldname )

Re: MICROSOFT SQL and DBF using at the same time

Verfasst: Di, 28. Nov 2017 13:27
von engindenizoglu
@1,1 say FieldName(SIPARISOLUSTURMATARIHI) ---->I GET THIS ERROR BELOW !!!
WAIT "--"

------------------------------------------------------------------------------
ERROR LOG of "C:\ALASKA2\00-TRIALS\SQL-X02\SQL-X02.exe" Date: 11/28/2017 15:26:07

Xbase++ version : Xbase++ (R) Version 2.00.853
Operating system : Windows 10 1607 Build 14393
------------------------------------------------------------------------------
oError:args :
-> VALTYPE: C VALUE: 20140603
oError:canDefault : Y
oError:canRetry : N
oError:canSubstitute: N
oError:cargo : NIL
oError:description : Parameter has a wrong data type
oError:filename :
oError:genCode : 2
oError:operation : FIELDNAME
oError:osCode : 0
oError:severity : 2
oError:subCode : 1025
oError:subSystem : BASE
oError:thread : 1
oError:tries : 0
------------------------------------------------------------------------------
CALLSTACK:
------------------------------------------------------------------------------
Called from MAIN(97)

Re: MICROSOFT SQL and DBF using at the same time

Verfasst: Di, 28. Nov 2017 13:45
von Martin Altmann
Engin,
you have to provide an integer as parameter indicating the field you want to know the name of!
So in your example:

Code: Alles auswählen

WERNER="SELECT TOP 100 SIPARISOLUSTURMATARIHI,MOULDTYPE,ORDERNO,ORDERITEMNO,CUSTOMERNO,STOCKCODE,PRODUCTGROUP,OPENTOTAL,TOTAL,CURRENCY,QUANTITY,OPENQUANTITY,SALESENGINEER,DELIVERY_YEAR,DELIVERY_MONTH,DELIVERY_DAY FROM ACIK_SATISSIPARISLERI;" /

USE (WERNER) VIA ODBCDBE
first field is SIPARISOLUSTURMATARIHI
second field is MOULDTYPE
...
last but one field is DELIVERY_MONTH
last field is DELIVERY_DAY
This means, that FieldName( 1 ) should give you "SIPARISOLUSTURMATARIHI"
FieldName( 2 ) should give you "MOULDTYPE"
...
FieldName( 15 ) should give you "DELIVERY_MONTH"
FieldName( 16 ) should give you "DELIVERY_DAY"

Therefore your code to identify the name of the field causing troubles should be:

Code: Alles auswählen

@1,1 say FieldName(1)
Çok selamlar,
Martin

Re: MICROSOFT SQL and DBF using at the same time

Verfasst: Di, 28. Nov 2017 13:51
von engindenizoglu
i get written for

?fieldname(1) --> SIPARISOLUSTURMATARIHI

Re: MICROSOFT SQL and DBF using at the same time

Verfasst: Di, 28. Nov 2017 14:46
von komnick
Engin,

try
REPLACE ZAFER->ON9 WITH 9->(FIELDGET(1))
instead of
REPLACE ZAFER->ON9 WITH 9->(SIPARISOLUSTURMATARIHI)

Gruß
Martin

Re: MICROSOFT SQL and DBF using at the same time

Verfasst: Di, 28. Nov 2017 17:58
von engindenizoglu
?type((FIELDGET(1))) ----> N (numeric field)
This field is a numeric field but during skip sometimes it appears like EMPTY.
That's why i get errors. Whenever i added EMPTY condition it worked but the interesting part is numbers look like empty even i
see that there is a nr data.

Whenever the field mouldtype= NIL ---> the SIPARISOLUSTURMATARIHI appears empty=.t.
Whenever the field mouldtype="asdsd" ---> not NIL ----> SIPARISOLUSTURMATARIHI appears a N (numeric field).

It sounds unlogical but this what i have observed (from the3000 recno's).

The sample below works but if the field mouldtype= NIL ( emtpy(mouldtype)=.T. )
the field SIPARISOLUSTURMATARIHI appears empty=.t. too ; even it's full with a numeric value.....

-----------------------------------------------------------------------------------------------------------

Code: Alles auswählen

    SELECT 7      /*     zafer.dbf      */
  
    SELECT 9      /*   SQL -  werner.dbf   */
    go top

DO WHILE .not EOF() 

  SELECT 9         /*   SQL -  werner.dbf   */
 
  IF EMPTY(FIELDGET(1))=.T.
         BOS=0                                                        [b]----> IT GETS LIKE there is no such a  field[/b]
        ELSE
         BOS=VAL(SIPARISOLUSTURMATARIHI)             [b] ----> here its NUMERIC[/b]
         @11,10 SAY type((FIELDGET(1)))
  ENDIF

   SELECT (ZAFER)         /*  zafer.dbf - DBFDBE  */
      APPEND BLANK
      IF NETERR()=.F.
          REPLACE ZAFER->ON8 WITH 9->TOTAL
          REPLACE ZAFER->ON10 WITH SUBSTR(9->SALESENGINEER,1,4)
          REPLACE ZAFER->SIPTAR WITH BOS       
          DBUNLOCK()
      ENDIF

ENDDO
--------------------------------------------------------------------------------------------------

Re: MICROSOFT SQL and DBF using at the same time

Verfasst: Di, 28. Nov 2017 19:27
von AUGE_OHR
hi

Xbase++ does not have all Field Type which a SQL Server have.
show use "Original" SQL Table Definition what Type each Field have.

Re: MICROSOFT SQL and DBF using at the same time

Verfasst: Di, 28. Nov 2017 20:16
von Tom
The ODBCDBE can be configured for how to deal with NULL values. Check the docs.

Re: MICROSOFT SQL and DBF using at the same time

Verfasst: Di, 28. Nov 2017 21:01
von engindenizoglu
Whenever a NULL is equal to a field other fields will be effected too.

I think this should be not a big deal fixing those kinds of problems for XBASE ++ ALASKA TEAM.

From now on I will continue my trials with SQL LIBRARY...