I'm trying to create oracle data dump files programmatically, using Oracle's SQLcl. The script looks like:
SET SQLFORMAT XML
SPOOL 'ABC.XML'
SELECT * FROM ABC;
SPOOL OFF
SPOOL 'XYZ.XML'
SELECT * FROM XYZ;
SPOOL OFF
//MORE TABLES BELOW
The command looks like:
exit | "path\to\sqlcl\folder\bin\sql.exe" username/password@connection_string @"path\to\data\dump\script\datadumpscript.sql"
By executing the command in CMD (windows 10), it works just fine.
The code executing logic is from this thread, converted to vb.net:
Private Shared Sub ExecuteCommand(ByVal command As String)
Dim exitCode As Integer
Dim processInfo As ProcessStartInfo
Dim process As Process
processInfo = New ProcessStartInfo("cmd.exe", "/c """ & command & """")
processInfo.CreateNoWindow = True
processInfo.UseShellExecute = False
processInfo.RedirectStandardError = True
processInfo.RedirectStandardOutput = True
process = Process.Start(processInfo)
process.WaitForExit()
Dim output As String = process.StandardOutput.ReadToEnd()
Dim [error] As String = process.StandardError.ReadToEnd()
exitCode = process.ExitCode
System.Diagnostics.Debug.WriteLine("output>>" & (If(String.IsNullOrEmpty(output), "(none)", output)))
System.Diagnostics.Debug.WriteLine("error>>" & (If(String.IsNullOrEmpty([error]), "(none)", [error])))
System.Diagnostics.Debug.WriteLine("ExitCode: " & exitCode.ToString(), "ExecuteCommand")
process.Close()
End Sub
When calling from code, by passing in the command above, the program does go to "process.WaitForExit()" and blocks, but only the first file in the spool script gets created with size of 0, the file gets locked by JAVA binary, and nothing happens after that. The exporting process doesn't seem to be running.
Any suggestion is appreciated. Thank you.