views:

1666

answers:

2

Hi,
I'm gonna get a backup with below method :

void BackupDatabase(string sConnect, string dbName, string backUpPath)
{
    using (SqlConnection cnn = new SqlConnection(sConnect))
    {
        cnn.Open();
        dbName = cnn.Database.ToString();

        ServerConnection sc = new ServerConnection(cnn);
        Server sv = new Server(sc);

        // Create backup device item for the backup
        BackupDeviceItem bdi = new BackupDeviceItem(backUpPath, DeviceType.File);

        // Create the backup informaton
        Microsoft.SqlServer.Management.Smo.Backup bk = new Backup();
        bk.PercentComplete += new PercentCompleteEventHandler(percentComplete);
        bk.Devices.Add(bdi);
        bk.Action = BackupActionType.Database;
        bk.PercentCompleteNotification = 1;
        bk.BackupSetDescription = dbName;
        bk.BackupSetName = dbName;
        bk.Database = dbName;
        //bk.ExpirationDate = DateTime.Now.AddDays(30);
        bk.LogTruncation = BackupTruncateLogType.Truncate;
        bk.FormatMedia = false;
        bk.Initialize = true;
        bk.Checksum = true;
        bk.ContinueAfterError = true;
        bk.Incremental = false;

        // Run the backup
        bk.SqlBackup(sv);//Exception
    }
}

But an exception has occurred :

Microsoft.SqlServer.Management.Smo.FailedOperationException: Backup failed for Server '\\.\pipe\3F103E6E-3FD4-47\tsql\query'

additional info about the Exception:

{Microsoft.SqlServer.Management.Smo.FailedOperationException: Backup failed for Server '\\.\pipe\3F103E6E-3FD4-47\tsql\query'. ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.SqlServer.BatchParser, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified.
File name: 'Microsoft.SqlServer.BatchParser, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91'
at Microsoft.SqlServer.Management.Common.ServerConnection.GetStatements(String query, ExecutionTypes executionType, Int32& statementsToReverse)
at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(String sqlCommand, ExecutionTypes executionType)
at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(StringCollection sqlCommands, ExecutionTypes executionType)
at Microsoft.SqlServer.Management.Smo.ExecutionManager.ExecuteNonQuery(StringCollection queries)
at Microsoft.SqlServer.Management.Smo.ExecutionManager.ExecuteNonQueryWithMessage(StringCollection queries, ServerMessageEventHandler dbccMessageHandler, Boolean errorsAsMessages)
at Microsoft.SqlServer.Management.Smo.BackupRestoreBase.ExecuteSql(Server server, StringCollection queries)
at Microsoft.SqlServer.Management.Smo.Backup.SqlBackup(Server srv)

=== Pre-bind state information ===
LOG: User = MDS-PC\MDS
LOG: DisplayName = Microsoft.SqlServer.BatchParser, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91
(Fully-specified)
LOG: Appbase = file:///D:/My Works/C#/Win Form/Reza Restaurant/RezaRestaurant/bin/Release/
LOG: Initial PrivatePath = NULL
Calling assembly : Microsoft.SqlServer.ConnectionInfo, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: D:\My Works\C#\Win Form\Reza Restaurant\RezaRestaurant\bin\Release\RezaRestaurant.vshost.exe.Config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v2.0.50727\config\machine.config.
LOG: Post-policy reference: Microsoft.SqlServer.BatchParser, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91
LOG: Attempting download of new URL file:///D:/My Works/C#/Win Form/Reza Restaurant/RezaRestaurant/bin/Release/Microsoft.SqlServer.BatchParser.DLL.
LOG: Attempting download of new URL file:///D:/My Works/C#/Win Form/Reza Restaurant/RezaRestaurant/bin/Release/Microsoft.SqlServer.BatchParser/Microsoft.SqlServer.BatchParser.DLL.
LOG: Attempting download of new URL file:///D:/My Works/C#/Win Form/Reza Restaurant/RezaRestaurant/bin/Release/Microsoft.SqlServer.BatchParser.EXE.
LOG: Attempting download of new URL file:///D:/My Works/C#/Win Form/Reza Restaurant/RezaRestaurant/bin/Release/Microsoft.SqlServer.BatchParser/Microsoft.SqlServer.BatchParser.EXE.

--- End of inner exception stack trace ---
at Microsoft.SqlServer.Management.Smo.Backup.SqlBackup(Server srv)
at RezaRestaurant.Form_تنظیمات_نرم_افزار.BackupDatabase(String sConnect, String dbName, String backUpPath) in D:\My Works\C#\Win Form\Reza Restaurant\RezaRestaurant\Forms\تنظیمات_نرم_افزار.cs:line 260
at RezaRestaurant.Form_تنظیمات_نرم_افزار.button_تهیه_نسخه_پشتیبان_Click(Object sender, EventArgs e) in D:\My Works\C#\Win Form\Reza Restaurant\RezaRestaurant\Forms\تنظیمات_نرم_افزار.cs:line 177}

Would you please guide me ? Thanks.

+1  A: 

The error message is pretty much conclusive:

Could not load file or assembly 'Microsoft.SqlServer.BatchParser, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified.

Is SMO installed correctly?

Are you running on a 64 bit system?

Have you installed the 2008 version of the SMO Components?

You can down the 64 bit version of SMO from here: Microsoft SQL Server 2008 Feature Pack, October 2008

Mitch Wheat
SMO is installed correctly.I'm running on a Win7 64 bit.I haven't installed the 2008 Version of the SMO componenet, I've just installed VS2008 SP1.
Mohammad
Have you installed the 64 bit version of SMO?
Mitch Wheat
No, I haven't. If I install it , the release file must run on a 64 Windows version only ?
Mohammad
If you haven't installed it, then it not going to work.
Mitch Wheat
Would you mind posting the link of downloading 64 bit version of SMO ?
Mohammad
Thanks for the link, If I install it , the release exe file must only run on a Windows 64 bit version?
Mohammad
I installed the package "X64 Package (SharedManagementObjects.msi) - 3895 KB", but I still receive the exception again.
Mohammad
A: 

I had to install this package :

X64 Package (SQLServer2005_XMO_x64.msi) - 14675 KB

My problem was solved.

Mohammad