拷贝功能是无法实现的了,因为*.ldf和*.mdf被MSSQLServer打开了。不允许拷贝。

解决方案 »

  1.   

    你不能对数据文件直接进行备份,要使用SQL Server提供的控件或者SQL语句进行备份。
    具体是那个我一时记不起来了;总之使用上述方式就可以将数据库备份功能嵌套到你的程序里面。
      

  2.   

    那就把SQL SERVER先关掉,然后拷贝不就得了。
    关使用的命令是请你到安装SQL SERVER的目录下80/TOOL/BINN/SCM.exe实现,6是关,1是开具体参数直接双击即可,程序中用CreateProcess执行就可以实现。
      

  3.   

    利用Sql语句进行备份。Backup 和 Restore
      

  4.   

    BACKUP
    Backs up an entire database, transaction log, or one or more files or filegroups. For more information about database backup and restore operations, see Backing Up and Restoring Databases. Syntax
    Backing up an entire database:BACKUP DATABASE { database_name | @database_name_var } 
    TO < backup_device > [ ,...n ] 
    [ WITH 
        [ BLOCKSIZE = { blocksize | @blocksize_variable } ] 
        [ [ , ] DESCRIPTION = { 'text' | @text_variable } ] 
        [ [ , ] DIFFERENTIAL ] 
        [ [ , ] EXPIREDATE = { date | @date_var } 
            | RETAINDAYS = { days | @days_var } ] 
        [ [ , ] PASSWORD = { password | @password_variable } ] 
        [ [ , ] FORMAT | NOFORMAT ] 
        [ [ , ] { INIT | NOINIT } ] 
        [ [ , ] MEDIADESCRIPTION = { 'text' | @text_variable } ] 
        [ [ , ] MEDIANAME = { media_name | @media_name_variable } ] 
        [ [ , ] MEDIAPASSWORD = { mediapassword | @mediapassword_variable } ] 
        [ [ , ] NAME = { backup_set_name | @backup_set_name_var } ] 
        [ [ , ] { NOSKIP | SKIP } ] 
        [ [ , ] { NOREWIND | REWIND } ] 
        [ [ , ] { NOUNLOAD | UNLOAD } ] 
        [ [ , ] RESTART ] 
        [ [ , ] STATS [ = percentage ] ] 
    ]Examples
    A. Back up the entire MyNwind database
    Note  The MyNwind database is shown for illustration only.
    This example creates a logical backup device in which a full backup of the MyNwind database is placed.-- Create a logical backup device for the full MyNwind backup.
    USE master
    EXEC sp_addumpdevice 'disk', 'MyNwind_1', 
       DISK ='c:\Program Files\Microsoft SQL Server\MSSQL\BACKUP\MyNwind_1.dat'-- Back up the full MyNwind database.
    BACKUP DATABASE MyNwind TO MyNwind_1
      

  5.   

    RESTORE
    Restores backups taken using the BACKUP command. For more information about database back up and restore operations, see Backing Up and Restoring Databases.Syntax
    Restore an entire database:RESTORE DATABASE { database_name | @database_name_var } 
    [ FROM < backup_device > [ ,...n ] ] 
    [ WITH 
        [ RESTRICTED_USER ] 
        [ [ , ] FILE = { file_number | @file_number } ] 
        [ [ , ] PASSWORD = { password | @password_variable } ] 
        [ [ , ] MEDIANAME = { media_name | @media_name_variable } ] 
        [ [ , ] MEDIAPASSWORD = { mediapassword | @mediapassword_variable } ] 
        [ [ , ] MOVE 'logical_file_name' TO 'operating_system_file_name' ] 
                [ ,...n ] 
        [ [ , ] KEEP_REPLICATION ] 
        [ [ , ] { NORECOVERY | RECOVERY | STANDBY = undo_file_name } ] 
        [ [ , ] { NOREWIND | REWIND } ] 
        [ [ , ] { NOUNLOAD | UNLOAD } ] 
        [ [ , ] REPLACE ] 
        [ [ , ] RESTART ] 
        [ [ , ] STATS [ = percentage ] ] 
    ]A. Restore a full database
    Note  The MyNwind database is shown for illustration.
    This example restores a full database backup.RESTORE DATABASE MyNwind 
       FROM MyNwind_1B. Restore a full database and a differential backup
    This example restores a full database backup followed by a differential backup. In addition, this example shows restoring the second backup set on the media. The differential backup was appended to the backup device that contains the full database backup.RESTORE DATABASE MyNwind
       FROM MyNwind_1
       WITH NORECOVERY
    RESTORE DATABASE MyNwind
       FROM MyNwind_1
       WITH FILE = 2
      

  6.   

    dz_w(快乐之星) ,我执行不了,请你详细写一下CreateProcess,可不可以?
      

  7.   

    用SQL语句, 不要用文件拷贝, 同guoxiny(狼) 
      

  8.   

    use TreeDB;
    exec sp_addumpdevice 'disk','myTreeDB2','d:\home\ljs\myTreeDB.bak'
    backup database TreeDB to myTreeDB2;SQL语句。