CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2001
    Posts
    31

    urgent help BCP UTILITY SQLDMO

    HI...

    I HAD THIS CODE.. AND MSG ME THIS ERROR:
    CONNECTION IS NOT ENABLED FOR BCP
    CAN ANYBODY HELP ME.!! IT´S URGENT!!

    ---

    Dim objServer as new SQLDMO.SQLServer
    Dim objBCP as new SQLDMO.BulkCopy
    Dim objDB as SQLDMO.Database

    ''if file doesn't exist and it's an import,
    ''don't waste time
    'If stroption = true then
    If exporta.Value = false And Dir(selectedFile) = "" then Exit Sub
    'else
    'Exit Sub
    on error GoTo ErrorHandler
    objServer.Connect ServerName, UserName, Password
    objServer.EnableBcp = true

    set objDB = objServer.Databases(DatabaseName)

    With objBCP
    .ColumnDelimiter = "|"
    .UseExistingConnection = true
    '.DataFilePath = "*.txt"
    .DataFilePath = selectedFile
    .UseBulkCopyOption = true

    End With

    If exporta.Value = false then
    ' objDB.Tables(Tablename).ImportData objBCP
    objDB.Tables(Tablename).ExportData objBCP
    else
    ' objDB.Tables(Tablename).ExportData objBCP
    objDB.Tables(Tablename).ImportData objBCP
    End If
    End




    ----



  2. #2
    Join Date
    Aug 2001
    Posts
    31

    Re: urgent help BCP UTILITY SQLDMO

    ok.. its me again... if somebody saw this ..

    this is the right code... ( working)

    Dim Count as Long
    Dim Progress as Long
    Dim lTimer as Long

    'Instanciamos los obetos
    set objBCP = new SQLDMO.BulkCopy
    set objServer = new SQLDMO.sqlserver
    set objDB = new SQLDMO.Database

    on error GoTo ErrorHandler

    With objServer
    .EnableBcp = true
    .LoginSecure = true
    .Connect ServerName, UserName, Password
    End With
    set objDB = objServer.Databases(DatabaseName)

    With objBCP
    .SetCodePage SQLDMOBCP_OEM
    .UseBulkCopyOption = true
    .ColumnDelimiter = "|"
    .DataFileType = SQLDMODataFile_SpecialDelimitedChar
    .DataFilePath = FArchivo.Path & "\" & selectedFile
    .ErrorFilePath = "c:\errores.log"
    .ImportRowsPerBatch = 1000
    .RowDelimiter = vbCrLf 'Carriage return
    .ServerBCPDataFileType = SQLDMOBCPDataFile_Native
    .ServerBCPKeepNulls = true
    .SuspendIndexing = false
    .UseExistingConnection = true
    .LogFilePath = "C:\logs.log"
    .TruncateLog = true
    End With


    If optexporta.Value = true then
    Screen.MousePointer = vbHourglass
    itotalregistros = objDB.Tables(Tablename).ExportData(objBCP)
    Debug.print "itotalregistros" & itotalregistros

    objServer.Disconnect
    set objServer = nothing
    else
    If optimportar.Value = true then
    Screen.MousePointer = vbHourglass
    prbar.Visible = true
    itotalregistros = objDB.Tables(Tablename).ImportData(objBCP)
    for Progress = 1 to 100
    prbar.Value = Progress
    lTimer = timeGetTime
    Do: Loop Until timeGetTime - lTimer > 100
    DoEvents 'Allows user to change styles etc whilst in progress
    next Progress
    MsgBox "Datos Importados:" & itotalregistros
    Screen.MousePointer = vbDefault
    objServer.Disconnect 'Desconectamos al servidor
    objServer.Close 'Cerramos al servidor
    else
    End If
    set objServer = nothing 'Liberamos
    set objBCP = nothing
    set objDB = nothing
    End If


    cn.Close ' cerramos la conexion
    set cn = nothing 'liberamos la conexion
    MsgBox "Desea volver al menu?"

    End


    ErrorHandler:

    Call MsgBox("Descripción :" & Err.Description, vbCritical + vbOKOnly, "error ")
    set objBCP = nothing
    set objServer = nothing
    set objDB = nothing
    End
    End Sub





  3. #3
    Join Date
    Sep 2008
    Posts
    1

    Exclamation Re: urgent help BCP UTILITY SQLDMO

    What value to be set for ImportRowsPerBatch Parameter.
    If i set ImportRowsPerBatch = 1000 then BCP Import Only 2000 Rows from the Given file.
    Or If i set ImportRowsPerBatch = 2000 then BCP Import Only 4000 Rows from the Given file.
    the ratio is 1:2 . if my file has more than double records then it doent import all records. only twice of that parameter value records are getting imported using. BCP.
    If file has less records then it imports successfully..
    What i do???

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured