B4J Question [SOLVED] Resumable sub question

Lahksman

Active Member
Licensed User
Longtime User
Hi all

I have created a small tool for myself for backing up my MS SQL databases.
Now I'm trying to implement resumable subs.

My jSQL library is updated to 1.50. This is my code so far. My backups are created but I don't know which event to use in the wait for.
Basicly I would like to transfer the output of my backup to a logfile as in the SQL management studio.

B4X:
Sub BackupDbase(database As String, loc As String)
    Dim query As String = $"BACKUP DATABASE ["$ & database & $"] TO DISK = N'"$ & loc & $"\"$ & database & $".bak' WITH NOFORMAT, INIT,  SKIP, NOREWIND, NOUNLOAD,  STATS = 10"$
    conn.ExecNonQuery2(query,Null)
    wait For (conn) conn_ready (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String) 'Which event should be used here??
    If Success And ExitCode = 0 Then
        Log("Success")
        Log(StdOut)
    Else
        Log("Error: " & StdErr)
    End If
End Sub

Output SQL management studio
B4X:
10 percent processed.
20 percent processed.
30 percent processed.
40 percent processed.
50 percent processed.
60 percent processed.
70 percent processed.
80 percent processed.
90 percent processed.
Processed 23840 pages for database 'CAFCA', file 'CAFCA_Data' on file 1.
100 percent processed.
Processed 2 pages for database 'CAFCA', file 'CAFCA_Log' on file 1.
BACKUP DATABASE successfully processed 23842 pages in 3.650 seconds (51.029 MB/sec).
 

Lahksman

Active Member
Licensed User
Longtime User
Ok, changed my code as shown below.
Event is being fired.
B4X:
    Dim query As String
    Dim Cursor As ResultSet
    Cursor = conn.ExecQuery2("SELECT name FROM master.dbo.sysdatabases where name <> ? and name <> ? and name <> ? and name <> ?", Array As String("master","tempdb","model","msdb"))
    Do While Cursor.NextRow
        Log(Cursor.GetString("name"))
        query = $"BACKUP DATABASE ["$ & Cursor.GetString("name") & $"] TO DISK = N'"$ & path & $"\"$ & Cursor.GetString("name") & $".bak' WITH NOFORMAT, INIT,  SKIP, NOREWIND, NOUNLOAD,  STATS = 10"$
        conn.AddNonQueryToBatch(query, Null)
        query = $"BACKUP LOG ["$ & Cursor.GetString("name") & $"] TO DISK = N'"$ & path & $"\"$ & Cursor.GetString("name") & $".trn' WITH NOFORMAT, INIT,  SKIP, NOREWIND, NOUNLOAD,  STATS = 10"$
        conn.AddNonQueryToBatch(query, Null)
    Loop
    Dim SenderFilter As Object = conn.ExecNonQueryBatch("SQL")
    Wait For (SenderFilter) SQL_NonQueryComplete (Success As Boolean)
    If Success Then
        Log("NonQuery: " & Success)
        ExitApplication
    Else
        Log("NonQuery: " & Success)
    End If

Now I only have to figure out if it's possible to catch the output (not a cursor) of the backup. That way I can create logfiles.
 
Upvote 0
Top