Results 1 to 4 of 4
Feb 17, 2011, 04:46 #1
Calling Batch file from Asp.Net using VB.net in .Net 1.1 Application
I have to develop a application using Asp.Net and VB.Net in .Net 1.1.
My aim is that ,I have one CSV File i want to read the CSV file and bulk insert into Oracle Database.
I use Batch file which contain
sqlldr userid=username/password@TNSNAME control=BatchFile.ctl LOG=BatchFile.log
In c# of .Net 2005 is working fine.
If i double click on the Batch file then also data inserting into the table.
Both the case is fine but same thing i write in VB.Net.
The code is follows
' ******** Data moving from CSV file to TMP table ************/ Try Dim startInfo As ProcessStartInfo = New ProcessStartInfo(Server.MapPath("~") + "/BatchFile/BATCH.BAT", "Command") startInfo.WorkingDirectory = Server.MapPath("~") + "/BatchFile" startInfo.CreateNoWindow = True startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden startInfo.UseShellExecute = True Dim batchExecute As Process = New Process batchExecute.StartInfo = startInfo If (batchExecute.Start()) Then batchExecute.WaitForExit() lblMessage.Text = "Data moved successfully" End If Catch csvEX As Exception lblMessage.Text = csvEX.Message End Try
Anyone can help me....
Feb 17, 2011, 21:38 #2
In CTL File(BatchFile.ctl) contains
load data infile 'C:/Ujjwal/AccessTime.csv' APPEND INTO TABLE TEST_BATCH FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' TRAILING NULLCOLS ( T_ID , EMP_ID, FIRST_NAME , LAST_NAME )
Apr 1, 2011, 02:56 #3Code:
'Data moving from CSV file to TMP table Dim startInfo As System.Diagnostics.ProcessStartInfo = New System.Diagnostics.ProcessStartInfo(Server.MapPath("~") + "/BatchFile/BATCHUPLOAD.BAT", "Command") startInfo.WorkingDirectory = Server.MapPath("~") + "/BatchFile" startInfo.CreateNoWindow = True startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden startInfo.UseShellExecute = True Dim batchExecute As System.Diagnostics.Process = New System.Diagnostics.Process batchExecute.StartInfo = startInfo If (batchExecute.Start()) Then
StackTrace " at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo) at System.Diagnostics.Process.Start() at seg1step.xx_import_xml_specs.btnUpload_Click(Object sender, EventArgs e) in D:\Web\mhe1stepQA\xx_import_xml_specs.aspx.vb:line 120" String
But if i go to folder and double click on BATCHUPLOAD.BAT file.Then it is working.Also, I developed it in c#.There is working but in VB.net it is not working.
Any help.Today is my delivery.( beacuse i did it in c# but in VB.net it gives this issue).
Apr 2, 2011, 11:17 #4
- Join Date
- Feb 2007
- 0 Post(s)
- 0 Thread(s)
It is not a good idea to start a batch file (or any other process for that matter) from within a web page. In fact, I believe that your problems may be related to very sensible security settings within .NET which will not by default allow you to spawn new processes.
If you have already developed the "bulk inserter" in C#, why don't you just refactor it so that the insertion logic can be called from the web page without starting external processes.
However, if this is a lot of data you will still have issues such as timeouts etc. In that case you are probably better off queuing up requests (using MSMQ or some database table as a poor-man's queue) and having an external process check the queue continuously (blocking MSMQ calls ) or polling the table.
If you need instant handling and you cannot use queues for some reason, an alternative may be to queue up a WorkItem. A WorkItem will be scheduled by IIS to run asap. Note, that it will occupy a dispatcher thread for the duration of the processing. You could issue a "ticket" to the requester can use Ajax callbacks or "meta" redirects to poll for WorkItem completion.