Page 1 of 1

error con adoimportfromdbf

Posted: Fri Aug 21, 2020 10:20 pm
by artu01
Mr. Rao
Estoy importando mi tabla mcodi.dbf a MSSQL de esta forma:

Code: Select all

  xPROVIDER := "SQLOLEDB"              
  xSOURCE   := "WIN-JET3FF08IIT"                
  xPASSWORD := "Pysa2019.
  xCATALOG  := "PysaBD"                
  xUSERID   := "sa"
  xConnect  := 'Provider='+xPROVIDER+';Data Source='+xSOURCE+';Initial Catalog='+xCATALOG+';User Id='+xUSERID+';Password='+xPASSWORD

  TRY
    oConnect:= CreateObject( "ADODB.Connection" )
    oConnect:Open( xConnect )
  CATCH oError
     MsgStop( oError:Description )
  END

    TRY
        oConnect:Execute( "DROP TABLE MCODI" )
    CATCH
    END
    FW_adoimportfromdbf(oConnect, "Z:\B1\MCODI.DBF")

Son 14942 registros por importar pero solo importa los primeros 12200 registros y alli me sale esta pantalla
Image
Adjunto link del dbf
https://we.tl/t-mkoKwPC2tU

Re: error con adoimportfromdbf

Posted: Sat Aug 22, 2020 2:10 pm
by nageswaragunupudi
This worked for me without any errors and should work for you also.

Code: Select all

   oCn := FW_OpenAdoConnection( { "MSSQL", xSource, xCatalog, xUserID, xPassword }, .t. )
   if oCn == nil
      ? "connect fail"
      return nil
   endif
   ? "Connected"
   MsgRun( "Importing MCODI.DBF", "MSSQL", { || lOk := FW_AdoImportFromDBF( oCn, "MCODI\MCODI.DBF" ) } )
   if lOk
      oRs   := FW_OpenRecordSet( oCn, "MCODI" )
      XBROWSER oRs TITLE oRs:Source SHOW RECID
      oRs:Close()
   endif
   oCn:Close()
 
Please use the function FW_OpenAdoConnection(...) as above instead of directly connecting.

Image

Re: error con adoimportfromdbf

Posted: Sat Aug 22, 2020 4:47 pm
by artu01
Mr. rao, thank you, i'll try your recommendation
Another question, seeing the table that you imported, i notice the column id but my dbf doesn't have that field?


Excellent photo of the penguin seeing the camera!
nageswaragunupudi wrote:This worked for me without any errors and should work for you also.

Code: Select all

   oCn := FW_OpenAdoConnection( { "MSSQL", xSource, xCatalog, xUserID, xPassword }, .t. )
   if oCn == nil
      ? "connect fail"
      return nil
   endif
   ? "Connected"
   MsgRun( "Importing MCODI.DBF", "MSSQL", { || lOk := FW_AdoImportFromDBF( oCn, "MCODI\MCODI.DBF" ) } )
   if lOk
      oRs   := FW_OpenRecordSet( oCn, "MCODI" )
      XBROWSER oRs TITLE oRs:Source SHOW RECID
      oRs:Close()
   endif
   oCn:Close()
 
Please use the function FW_OpenAdoConnection(...) as above instead of directly connecting.

Image

Re: error con adoimportfromdbf

Posted: Sun Aug 23, 2020 3:16 am
by nageswaragunupudi
By default, the function adds an autoincrement field ID as the primary key, if the DBF does not already have an auto-inc field.

Many a time we forget or ignore that is essential to have a primary key when we migrate to SQL databases and this feature simplifies the process of migration.

Still, we can override by specifying one of the other existing fields as the primary key.

But never, never create a table in any sql database without a primary key.

Re: error con adoimportfromdbf

Posted: Sun Aug 23, 2020 3:44 am
by artu01
nageswaragunupudi wrote: Still, we can override by specifying one of the other existing fields as the primary key.
Mr. Rao :
Into the importation How specify an field as the primary key ?

Thank you Master for your response