SQL Server Backup Database via ODBC
I am trying to write a program that can import and export a specific database, as well as users and logins, from a Microsoft SQL Server database. I have an abstraction layer between my code and ODBC that most of our other software uses. The abstraction layer is usually done with auto-shutdown and processes the transactions on its own, but since the BACKUP command doesn't like to run in any transaction, I use another layer method called executeDirect which starts it with autocommit.
The method uses the SQLExecDirect function to run the BACKUP command. When this is done, the function returns SUCCESS_WITH_INFO, as the BACKUP command likes to produce three lines of output. The code then tries to get the result using SQLGetDiagField and can collect the first row from record # 1, but there is no record # 2.
The last thing the method wants to do is reset the connection with autocommit off, but when it tries to do that, it gets an error: "The connection is busy with results from another command", SQL State is "HY000". So, obviously the connection wants to move the other two lines of output, but I don't know how.