Click here to Skip to main content
15,911,891 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have to get bulk data from text file and need to insert into Oracle table using SQLLoader. What do I need to add to my VB.Net solution to be able to execute SQL loader within my windows application?

I have written code using System.Diagnostic namespace to connect oracle data source and insert data using System.Diagnistic.Process. But records were not inserted. Please give me your inputs.

Code which I have used

MSIL
Dim proc As System.Diagnostics.Process = New System.Diagnostics.Process
Dim myCommand As String = "CMD.EXE"
proc.StartInfo = New ProcessStartInfo(myCommand)
'Set up arguments for CMD.EXE
'bytReturn = WshShell.Run("sqlldr " & strUser & "/" & strDatabasePassword & "@pwb_stg parfile=../parm/all.par errors=0", normal, wait)
proc.StartInfo.Arguments = "sqlldr PWBIMP@PWB_DEV/2010_MUU_ImpTest CONTROL=uhc_excl_ctl.txt"
proc.StartInfo.RedirectStandardInput = False
proc.StartInfo.RedirectStandardOutput = True
proc.StartInfo.RedirectStandardError = True
proc.StartInfo.UseShellExecute = False
proc.StartInfo.WorkingDirectory = "P:\CPD\CESP\parm"

Try
proc.Start()
proc.WaitForExit(2000)
If (proc.ExitCode = 0) Then
'MsgBox.Show("Successfully Inserted")
MsgBox("Successfully Inserted")
Else
MsgBox(proc.StandardError.ReadToEnd)
End If
Catch ex As Exception
MsgBox(ex.Message)


Control File Which I created (uhc_excl_ctl.txt)
SQL
LOAD DATA
INFILE uhc_excluded_ftin_list.txt
BADFILE uhc_excluded_ftin_list_log.txt
INTO table Test1
FIELDS TERMINATED BY  ","
(ProductName,ProductGroupName)


Thanks
Ramesh
Posted

Hi..,

why are invoking the cmd.exe.., no need to invoke the cmd.exe, you can directly invoke the sqlldr.exe to load data..

here am changing your code .., this is not tested. you have to debug in your pc .

MSIL
Dim proc As System.Diagnostics.Process = New System.Diagnostics.ProcessDim myCommand As String = "sqlldr.EXE"
proc.StartInfo = New ProcessStartInfo(myCommand)'Set up arguments for CMD.EXE'bytReturn = WshShell.Run("sqlldr " & strUser & "/" & strDatabasePassword & "@pwb_stg parfile=../parm/all.par errors=0", normal, wait)proc.StartInfo.Arguments = "PWBIMP@PWB_DEV/2010_MUU_ImpTest CONTROL=uhc_excl_ctl.txt"
proc.StartInfo.RedirectStandardInput = Falseproc.StartInfo.RedirectStandardOutput = Trueproc.StartInfo.RedirectStandardError = Trueproc.StartInfo.UseShellExecute = Falseproc.StartInfo.WorkingDirectory = "P:\CPD\CESP\parm"
Tryproc.Start()proc.WaitForExit(2000)If (proc.ExitCode = 0) Then'MsgBox.Show("Successfully Inserted")MsgBox("Successfully Inserted")ElseMsgBox(proc.StandardError.ReadToEnd)End IfCatch ex As ExceptionMsgBox(ex.Message)


try it.,
 
Share this answer
 
Hi Rajesh,

Thanks for the reply.

I replaced cmd.exe with sqlldr.exe. But application says, "the system cannot find specified file"

VB
What do I need to add to my VB.Net solution to be able to execute SQL loader within my windows application?


Thanks,
Ramesh.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900