Smo + remote Backup fails...

C

christof

Hello,
I'm trying to do a backup by connecting to remote instance, code looks
like that:

using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Common;
using System.Data.SqlClient;


string connString = "Server=172.17.0.193\\SQLEXPRESS,15555;
User ID=sa;Password=pass;Net=dbmssocn;
Integrated Security=false;Pooling=false"

SqlConnection sqlConn = new SqlConnection(connString);
ServerConnection srvConn = new ServerConnection(sqlConn);
Server srv = new Server(srvConn);

//it surely works fine, cause for each other operation, like displaying
//tables, databases, views and so on it is ok


Backup dbBackup = new Backup();

dbBackup.Action = BackupActionType.Database;
dbBackup.Database = ddlBackupDatabase.SelectedValue;

BackupDeviceItem dbBackupItem = new BackupDeviceItem();

dbBackupItem.DeviceType = DeviceType.File;
dbBackupItem.Name = Server.MapPath("Backup/filename.bak");

dbBackup.Devices.Add(dbBackupItem);

try
{
dbBackup.SqlBackup(srv);
}
catch (SmoException exc)
{
lblStatus.Text = exc.Message;
}

Unfortunately got an error :(

"Backup failed for Server '172.17.0.193\\SQLEXPRESS,15555'. "
Microsoft.SqlServer.Management.Common.SqlServerManagementException
{Microsoft.SqlServer.Management.Smo.FailedOperationException}
 
H

Hans Kesting

Hello,
I'm trying to do a backup by connecting to remote instance, code looks like
that:
[snip]
dbBackupItem.Name = Server.MapPath("Backup/filename.bak");

Using Server.MapPath you convert that relative path to an absolute one,
for your *local* (to the webserver) filesystem. As far as I know
SqlServer can only backup to files local to the (db-)server.


Hans Kesting
 
C

christof

Hans said:
Hello,
I'm trying to do a backup by connecting to remote instance, code looks
like that:
[snip]
dbBackupItem.Name = Server.MapPath("Backup/filename.bak");

Using Server.MapPath you convert that relative path to an absolute one,
for your *local* (to the webserver) filesystem. As far as I know
SqlServer can only backup to files local to the (db-)server.


Hans Kesting

Thanks, it's clear :p I've corrected it, but is there any possibility to
get (download) that backup file created saved on remote computer to the
server somehow?

Thank you
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top