how to get error message when DMO backup fails

  • when performing backup via DMO using C++, how can I get the error message when the backup fails?

    For example, using the following code

    HRESULT hr;

    hr = g_pSQLBackup->SQLBackup (g_pSQLServer);

    if FAILED(hr) {

    //unsuccessful, but how can I tell

    //the user what wrong?

    }

    Please help.

    Thanks,

    Bill

  • SQLCA

  • Not a C++ guy but wont the hresult give you an error code you can map to an error message?

    Andy

  • Sorry haven't looked to much into this but check out http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sqldmo/dmoref_cnst03_4c11.asp for SQL-DMO errors handling.

    "Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)

  • Hi, Thanks for the response, which lead me to solve the problem.

    James(Antares686): thanks for pointing me to MSDN where I found a solution.

    Andy: hresult does give me a value. But I can not find the mapping from that value to a description. e.g., when I try to backup to tape while no tape drive in the machine, the hresult value does not appear in the Error Code table pointed by James(Antares686).

    bodhayansharma: I am not sure how I can use SQLCA. I did not spend time on it.

    Thanks again

    Bill

  • Why not just add your own? Since you know the value it returns when that error happens, just add some user friendly test that you can use in your app.

    Andy

  • I do agree with Andy that should be just fine. However be carefull as this may have some extended message (usually doesn't) taht returns in addition to this error. If that is the case then the error could represent other problems (again pretty safe to say it isn't).

    "Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)

  • Good thing to add my messages based on the code is that it is easy for me to localize the message to present to the user.

    The reason I do not want to add my own:

    (1) I need explore all the failure scenario and test to get the error codes, too many situations to consider

    (2) I need make sure SQL Server 7.0 and 2000 give me the same error code

    (3) I need to make sure SQl Servers or operating systems do not change those numbers.

    that would be too much to investigate.

    Bill

  • Seems like you're always going to have those problems anyway. A method I use for utilities is handle the one or two errors I see most often, other than that just let the user know what went wrong and stop the processing.

    Andy

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply