SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru ujjwal's Avatar
    Join Date
    Oct 2004
    Location
    kolkata
    Posts
    821
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Calling Batch file from Asp.Net using VB.net in .Net 1.1 Application

    Dear All,

    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
    Code:
    sqlldr userid=username/password@TNSNAME control=BatchFile.ctl LOG=BatchFile.log
    In CTL file contains the table name and the executable CSV file Path.

    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
    Code:
    ' ******** 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
    No error is coming but no data is inserting into database's table.

    Anyone can help me....
    -::Ujjwal::-
    Visit My Site

  2. #2
    SitePoint Guru ujjwal's Avatar
    Join Date
    Oct 2004
    Location
    kolkata
    Posts
    821
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In CTL File(BatchFile.ctl) contains
    Code:
    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 
    )
    -::Ujjwal::-
    Visit My Site

  3. #3
    SitePoint Guru ujjwal's Avatar
    Join Date
    Oct 2004
    Location
    kolkata
    Posts
    821
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    '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
    From this line it throws Access is denied error.
    Code:
    	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
    Anyone can help me.
    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).

    Thanks,
    Ujjwal Das
    -::Ujjwal::-
    Visit My Site

  4. #4
    SitePoint Wizard
    Join Date
    Feb 2007
    Posts
    1,274
    Mentioned
    0 Post(s)
    Tagged
    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.


Bookmarks

Posting Permissions

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