error con adoimportfromdbf

Post Reply
artu01
Posts: 306
Joined: Fri May 11, 2007 8:20 pm
Location: Lima

error con adoimportfromdbf

Post 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
fwh 17.12, harbour 3.2.0, pelles C, bcc7, Ms-Sql
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: error con adoimportfromdbf

Post 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
Regards

G. N. Rao.
Hyderabad, India
artu01
Posts: 306
Joined: Fri May 11, 2007 8:20 pm
Location: Lima

Re: error con adoimportfromdbf

Post 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
fwh 17.12, harbour 3.2.0, pelles C, bcc7, Ms-Sql
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: error con adoimportfromdbf

Post 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.
Regards

G. N. Rao.
Hyderabad, India
artu01
Posts: 306
Joined: Fri May 11, 2007 8:20 pm
Location: Lima

Re: error con adoimportfromdbf

Post 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
fwh 17.12, harbour 3.2.0, pelles C, bcc7, Ms-Sql
Post Reply