Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 Other Development Tools
 Backup Database error using SQLDMO in C# .

Author  Topic 

QuachNguyen
Starting Member

15 Posts

Posted - 2007-10-11 : 14:33:29
Hi All

I'm new comer, I got this function on the internet , and I try to run it , but I got this error .


SQLDMO.Backup oBackup = new SQLDMO.BackupClass();
SQLDMO.SQLServer oSQLServer = new SQLDMO.SQLServerClass();
oSQLServer.LoginSecure = false;
oSQLServer.Connect("localhost", "sa", "852456****258654");
oBackup.Action = SQLDMO.SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database;
oBackup.Database = "Northwind";
oBackup.Files = @"C:\\Northwind.bak";
oBackup.BackupSetName = "Northwind";
oBackup.BackupSetDescription = "I don't know this one used for";
oBackup.Initialize = true;
oBackup.SQLBackup(oSQLServer);
MessageBox.Show("OK");



h.t.t.p://imagesshared.com/images/jdv1192127157z.JPG

I'm sure that my userID and my password to login my database is correct , And I also turn on SQL Service before .

How can I overcome this problem , I'm going to do my project in my school that having backup and restore database utility .

Thanks in advance .


spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-10-11 : 15:10:15
see if the sql browsr service is running.

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-10-11 : 15:31:38
I believe the problem is with your connection string: oSQLServer.Connect("localhost", "sa", "852456****258654");

I don't think you can refer to SQL Server as localhost. I believe for a local installation, you use (local). But just specify the hostname instead. Do you know if you installed the default instance or did you specify an instance name? If you specified an instance name, you'll need to use hostname\instancename.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

QuachNguyen
Starting Member

15 Posts

Posted - 2007-10-12 : 01:36:16
Thanks tkizer, spirit1 for replying .

oSQLServer.Connect("localhost", "sa", "852456****258654");


I think this problem occurs in this line , I try to modify this link to


oSQLServer.Connect(@"itcsharp\localhost","sa", "852456****258654");


But it still go this error .

@spirit1 :I see sql browser service is running in Windown service .

Thanks in advance .

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-10-12 : 01:39:09
localhost is most likely not your instancename. Did you install the default instance or a named instance when you installed SQL Server? If you can't remember, then check the SQL Server Configuration Manager tool. Look under SQL Server 2005 Network Configuration. Let us know what you have there.


Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

QuachNguyen
Starting Member

15 Posts

Posted - 2007-10-12 : 02:55:35
Now I do it successful . My instance named ITCSHARP , not localhost as the line below .

oSQLServer.Connect("ITCSHARP", "sa", "852456****258654");


Thanks tkizer, spirit1, you help me overcome this problem . Thanks
Go to Top of Page
   

- Advertisement -