Help CreateProcess API using BCP for SQL 6.5 
Author Message
 Help CreateProcess API using BCP for SQL 6.5

Hi to all and thank you in advance for any help.
Hi, I trying to run Ms Sql 6.5 Bcp command using the createprocess api call.
My problem is that it is not working. Please help. I can not use any shell
method to issued the bcp .
I am running an application that is running using an NT service ocx, and
that is why I need to the createprocess function to be to able bcp .
follow is my code and any help will be greatly appreciate.

Public Const NORMAL_PRIORITY_CLASS = &H20
    Public Const GENERIC_WRITE = &H40000000
    Public Const CREATE_ALWAYS = 2
    Public Const FILE_ATTRIBUTE_NORMAL = &H80
    Public Const MAX_BUFFER_SIZE = 20000
    Public Const FIELD_DELIMITER = "~|~"
    Public Const RECORD_DELIMITER = "~"
    Public Const CCINCREMENT = 500

    Public Const INFINITE = &HFFFF
    Public Const PROCESS_ALL_ACCESS = &HF0000 Or &H100000 Or &HFFF
    Public Const WAIT_FAILED = &HFFFFFFFF
    Public Const STILL_ACTIVE = &H103

    Public Const ERR_UNABLE_TO_PROCESS_DATA_FILE = 1
    Public Const ERR_MULTIPLE_RECORD_TYPE_FOUND = 2
    Public Const ERR_SAVING_DATA_TO_BCP_FILE = 3

Declare Function CreateProcess& Lib "kernel32" Alias "CreateProcessA" (ByVal
lpApplicationName As String, _

ByVal lpCommandLine As String, _

ByVal lpProcessAttributes As Long, _

ByVal lpThreadAttributes As Long, _

ByVal bInheritHandles As Long, _

ByVal dwCreationFlags As Long, _

lpEnvironment As Any, _

ByVal lpCurrentDirectory As String, _

lpStartupInfo As STARTUPINFO, _

lpProcessInformation As PROCESS_INFORMATION)

Declare Function WaitForInputIdle& Lib "user32" (ByVal hProcess As Long,
ByVal dwMilliseconds As Long)

Type STARTUPINFO
        cb As Long
        lpReserved As String
        lpDesktop As String
        lpTitle As String
        dwX As Long
        dwY As Long
        dwXSize As Long
        dwYSize As Long
        dwXCountChars As Long
        dwYCountChars As Long
        dwFillAttribute As Long
        dwFlags As Long
        wShowWindow As Integer
        cbReserved2 As Integer
        lpReserved2 As Byte
        hStdInput As Long
        hStdOutput As Long
        hStdError As Long
End Type

Type PROCESS_INFORMATION
        hProcess As Long
        hThread As Long
        dwProcessId As Long
        dwThreadId As Long
End Type

Declare Function GetExitCodeProcess& Lib "kernel32" (ByVal hProcess As Long,
lpExitCode As Long)
    Declare Function WaitForSingleObject& Lib "kernel32" (ByVal hHandle As
Long, ByVal dwMilliseconds As Long)
    Declare Function CloseHandle& Lib "kernel32" (ByVal hObject As Long)
    Declare Function GetLastError& Lib "kernel32" ()

Private Function CreateBcpProcess() As Boolean
dim strCommand as string
Dim res&
Dim sInfo As STARTUPINFO
Dim pInfo As PROCESS_INFORMATION
Dim sNull As String
Dim iResult As Long
Dim iExit As Long

strCommand = Commandtext = "bcp Cdr..eds_prov_revw_seg in " & _
"d:\testservice\edsdata\error\eds_prov_revw_seg.txt_980504_142806  -c -b5000
-m1000 -o" & _
"d:\testservice\edsdata\error\eds_prov_revw_seg.log_980504_142806" & " -t"""
& FIELD_DELIMITER & """ -r""" & _
RECORD_DELIMITER &
"\n"" -Ucdr_admin -Padmincdr -Sbigego -ed:\testservice\edsdata\error\eds_pro
v_revw_seg.err_980504_142806"

On Error GoTo Procedure_Exit:
sNull = vbNullString

With sInfo
    .cb = Len(sInfo)
    .lpReserved = 0
    .lpDesktop = 0
    .lpTitle = 0
    .dwFlags = 0
End With

res = CreateProcess(vbNullstring,_
                    strCommand, _
                    ByVal 0&, _
                    ByVal 0&, _
                    1&, _
                    NORMAL_PRIORITY_CLASS, _
                    ByVal 0&, _
                    ByVal 0&, _
                    sInfo, _
                    pInfo)

If res Then
        iResult = WaitForSingleObject(pInfo.hProcess, INFINITE)
        If iResult = WAIT_FAILED Then
            Err.Raise Err.LastDllError
        Else
            GetExitCodeProcess pInfo.hProcess, iExit
            Do While iExit = STILL_ACTIVE
                DoEvents
                GetExitCodeProcess pInfo.hProcess, iExit
            Loop
        End If

    CloseHandle pInfo.hProcess
    CloseHandle pInfo.hThread
    CreateBcpProcess = iExit
Else
    CreateBcpProcess = False
End If

Procedure_Exit:
    Exit Function

Procedure_Err:
'            Call Utilities.Unexpected_Error("EDS WaitOnProgram WAIT_FAILED
:WaitForSingleObject=" & _
'                                            Err.LastDllError,
Err.LastDllError, Err.Description, gLogFileName)
            CreateBcpProcess = False
            GoTo Procedure_Exit
end function



Sat, 21 Oct 2000 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Help - BulkCopying data to MS-SQL 6.5 using SQLOLE in VB6.0

2. USing ASP migrating from SQL 6.5 to SQL 7.0

3. Help using API CreateProcess ?

4. Locking in VB5 and SQL Server 6.5 using stored procs

5. Using VB5 and Sql Server 6.5

6. Dynaset/Snapshot problem using SQL Server 6.5

7. executing SQL Server 6.5 stored procedure using VB 5

8. connecting to MS SQL Server 6.5 using VB5

9. How to..Using VB5 with Sql server 6.5

10. Suggestions for a CASE Tool using VB 4/SQL Server 6.5

11. Crystal Distribution using SQL 6.5

 

 
Powered by phpBB® Forum Software