Software Development Network>> SQL Server>> Backup databases programatically.
You do know that you can overload the Server instantiation to direct it to the server you want to connect to, don't you
Example:
Dim srv As Serversrv = New Server("MyLapTop\Express")
In VB.Net you can also set the property in the ServerConnection object:
Dim srv As ServerDim srvConn As ServerConnection
srv = New Server
srvConn = srv.ConnectionContextsrvConn.LoginSecure = TruesrvConn.ServerInstance = "MyLapTop\Express"
Either one should work for you.
I am using the example code with minor modifications and can't get around the unable to connect error.... Has anyone run into this issue I have tried everything I can think of at this point and it just won't connect to the local instance.
Backup databases programatically.
Jasaldrich
victoravilanet
pink_flower4love
You do know that you can overload the Server instantiation to direct it to the server you want to connect to, don't you
Example:
Dim srv As Server
srv = New Server("MyLapTop\Express")
In VB.Net you can also set the property in the ServerConnection object:
Dim srv As Server
Dim srvConn As ServerConnection
srv = New Server
srvConn = srv.ConnectionContext
srvConn.LoginSecure = True
srvConn.ServerInstance = "MyLapTop\Express"
Either one should work for you.
SHAILESH KUMAR PANDEY
I am using the example code with minor modifications and can't get around the unable to connect error.... Has anyone run into this issue I have tried everything I can think of at this point and it just won't connect to the local instance.
Norman37050
Its so easy, I love Microsoft Tools.
using Microsoft.SqlServer.Management.Smo;
namespace SMOTest
{
class Program
{
static void Main()
{
Server svr = new Server();
Backup bkp = new Backup();
bkp.Action = BackupActionType.Database;
bkp.Database = "AdventureWorks";
bkp.DeviceType = DeviceType.File;
bkp.Devices.Add(@"c:\SMOTest.bak");
bkp.SqlBackup(svr);
}
}
}