Click to See Complete Forum and Search --> : urgent help BCP UTILITY SQLDMO


Karina Gámez
August 29th, 2001, 11:01 AM
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




----

Karina Gámez
September 21st, 2001, 06:50 PM
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

Rahul.sawant
September 26th, 2008, 04:19 AM
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???