[SOLVED] Functionality similar to C#'s Backup.SqlBackup()

  • Dear Qt programmers,

    I have an application that I wrote in C# and it uses "this":http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.backup.sqlbackup.aspx#Y0 specific method. It creates a backup of a MSSQL database. I wanted to port that app to Qt enabled C++ (which is more platform independent ;-) ). I've searched the forums and Googled for it and found nothing relevant - does Qt provide anything similar to this functionality? I need to be able to make a backup which can afterwards be restored using Management Studio for MSSQL Server or a similar piece of software.

    DBMS used is MSDE 2000 or MSSQL 2008.

    Thank you in advance for your suggestions.


    Edit: Not possible in Qt, but you can use osql.exe and start it within Qt if you like.

  • That's more a C/C++ question on Windows API. From Qt's side, there is no support for it, but you can use whatever C/C++ API you want in Qt based applications. It's still C/C++ :-)

  • Thanks Volker for your answer. I'm trying to create this backup using osql.exe application that is delivered with MSDE2000 and QProcess.

    Here's the code snippet:
    QProcess *dbBackupProcess = new QProcess();
    QStringList args; args << "-Uuser" << "-Ppassword" << "-Sdomain\SQLinstance" << "-Q "BACKUP DATABASE dbName TO DISK = 'E:\backupName.bak'"";
    dbBackupProcess->start("osql.exe", args);

    This unfortunately doesn't work. What am I doing wrong?

    Below command ran from the command prompt works good:
    @osql.exe -Uuser -Ppassword -Sdomain\SQLinstance -Q "BACKUP DATABASE dbName TO DISK = 'E:\backupName.bak'"@

    Edit: Okay, never mind. I'm finally getting somewhere. Will post an update soon.

    Edit#2: I guess I solved it:

    QString command = "osql.exe -UuserName -Ppassword -Sdomain\SQLinstance -Q "BACKUP DATABASE dbName TO DISK = 'E:\backupName.bak'"";
    int exitCode = QProcess::execute(command);

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.