Udostępnij przez


Transfer danych

The Transfer class is a utility class that provides tools to transfer objects and data.

Objects in the database schema are transferred by executing a generated script on the target server.Table data is transferred with a dynamically created DTS package.

The Transfer object contains all the functionality of the Transfer objects in DMO and additional SQL Server functionality.Jednak w przypadku obiektów SMO Transfer obiekt będzie miał DTS do transferu danych. Ponadto, metody i właściwości, które są używane do wykonywania transferów danych znajdują się na Transfer obiekt zamiast Database obiekt. Przenoszenie funkcji klas wystąpienie klasy narzędzia jest zgodna z jaśniejsze modelu obiektów, ponieważ kod dla określonych zadań jest ładowany tylko wtedy, gdy jest to wymagane.

The Transfer object does not support data transfers to a miejsce docelowe database that has a CompatibilityLevel() less than the wersja of the wystąpienie of SQL Server.

W szczególności

  • SQL Server 2005 i SQL Server 2008 nie obsługują transfer danych z baz danych CompatibilityLevel() Właściwość Version80().

  • SQL Server 2005 i SQL Server 2008 nie obsługują transfer danych z baz danych SQL Server w wersja 7.0.

Przykład

To use any code example that is provided, you will have to choose the programming environment, the programming template, and the programming language in which to create your application. For more information, see "How to: Create a Visual Basic SMO Project in Visual Studio .NET" or "How to: Create a Visual C# SMO Project in Visual Studio .NET" in SQL Server Books Online.

Przenoszenie schemat i dane z jednej bazy danych do komórki w języku Visual Basic

W tym przykładzie kodu pokazano, jak przenieść schemat oraz dane z jednej bazy do innej przy użyciu Transfer obiekt.

Przenoszenie schemat i dane z jednej bazy danych do komórki w środowisku Visual C#

W tym przykładzie kodu pokazano, jak przenieść schemat oraz dane z jednej bazy do innej przy użyciu Transfer obiekt.

//Connect to the local, default instance of SQL Server.

{ 
   Server srv = default(Server); 
   srv = new Server(); 
   //Reference the AdventureWorks database 
   Database db = default(Database); 
   db = srv.Databases("AdventureWorks"); 
   //Create a new database that is to be destination database. 
   Database dbCopy = default(Database); 
   dbCopy = new Database(srv, "AdventureWorksCopy"); 
   dbCopy.Create(); 
   //Define a Transfer object and set the required options and properties. 
   Transfer xfr = default(Transfer); 
   xfr = new Transfer(db); 
   xfr.CopyAllTables = true; 
   xfr.Options.WithDependencies = true; 
   xfr.Options.ContinueScriptingOnError = true; 
   xfr.DestinationDatabase = "AdventureWorksCopy"; 
   xfr.DestinationServer = srv.Name; 
   xfr.DestinationLoginSecure = true; 
   xfr.CopySchema = true; 
   //Script the transfer. Alternatively perform immediate data transfer 
   // with TransferData method. 
   xfr.ScriptTransfer(); 
}