通过C#进行SQL Server备份。找不到文件,无法加载Microsoft.SqlServer.BatchParser么?!

时间:2012-01-15 10:32:28

标签: c# sql-server-2005

我正在尝试创建备份。我不明白我得到的错误是什么。哪找不到?!

这是错误消息: http://img717.imageshack.us/img717/1772/sql1.jpg

我的代码:

    public void BackupDatabase(String destinationPath)
    {
        try
        {
            //MY SERVER
            String userName = "NNIT-Admin";
            String password = "password";
            String serverName = @"RITZEL-PC\SQLEXPRESS";

            ServerConnection connection = new ServerConnection(serverName, userName, password);
            Server sqlServer = new Server(connection);

            Backup BackupMgr = new Backup();
            BackupMgr.Devices.AddDevice(destinationPath, DeviceType.File);
            BackupMgr.Database = @"RITZEL-PC\SQLEXPRESS\Databases\D:\MY_THESIS\WORKING FILES\NNIT-RMS.MDF";
            BackupMgr.Action = BackupActionType.Database;
            BackupMgr.SqlBackup(sqlServer);
        }
        catch (Exception ex) 
        {
            MessageBox.Show(ex.Message + " " + ex.InnerException);
        }
    }

    private void BackUp_Btn_Click(object sender, EventArgs e)
    {
        String destinationPath = @"D:\";

        BackupDatabase(destinationPath);

    }

1 个答案:

答案 0 :(得分:1)

根据a quick Google search,您需要安装64位SMO组件:

  

我在这里找到了解决方案:

     

http://www.microsoft.com/downloads/details.aspx?familyid=D09C1D60-A13C-4479-9B91-9E8B9D835CDC&displaylang=en

     

下载并安装

     

X64包(SQLServer2005_XMO_x64.msi) - 14675 KB

     

这将安装64位smo对象。