2

Situation is simple.
I have application in C# that use MS SQL Database. For some reason i need to add some backup/restore function. I don't have directly access to MS SQL instance.

Is there any other simply way to backup database from C#? Maybe some script can create tables, structures and data, that can be use on other machine?

I need to do this only via C# (standard .NET references). No third party applications.

animuson
  • 53,861
  • 28
  • 137
  • 147
revelvice
  • 368
  • 5
  • 18

2 Answers2

3

No, there isn't.

If you don't have permissions or even a login to the SQL Server instance, you will not be able to run any sort of BACKUP commands against the database.

Backing up the file system (the mdf, ldf, and ndf's) isn't a sufficient backup strategory for SQL Server.

1

You can use SMO for this (provided you have the appropriate access permissions):

To run the SqlBackup method, users must have BACKUP DATABASE or BACKUP LOG permissions on the database, or be a member of the db_owner and db_backupoperator fixed database role and the sysadmin fixed server role.

Also:

C# SMO backup of remote database to local machine.

Getting Started with SMO in SQL 2005 - Backups

Community
  • 1
  • 1
Mitch Wheat
  • 295,962
  • 43
  • 465
  • 541
  • users need appropriate permissions to do anything! :) – Mitch Wheat Oct 18 '11 at 14:20
  • exactly :) looks like the OP is out of luck with no permissions then. –  Oct 18 '11 at 14:21
  • possibly. It's still a valid answer, permissions or not. – Mitch Wheat Oct 18 '11 at 14:21
  • Thank You all for answer and comments. My SQL user have permission to BACKUP DATABASE statement, but don't have access to file that will be created on server side so this is bad. SMO is not a option to. As @Mitch Wheat link said You can't backup remote database to local machine. I think i need to try with WriteXml and ReadXml with DataSet and create script to get/set data and structure from source to destination. – revelvice Oct 19 '11 at 06:22