Đang chuẩn bị liên kết để tải về tài liệu:
Microsoft SQL Server 2005 Developer’s Guide- P50
Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Microsoft SQL Server 2005 Developer’s Guide- P50:SQL Server 2005 is a feature-rich release that provides a host of new tools and technologies for the database developer. This book is written to help database developers and DBAs become productive immediately with the new features and capabilities found in SQL Server 2005. | Chapter 12 Developing with SMO 469 Private Sub cmdCreateDB_Click ByVal sender As System.Object ByVal e As System.EventArgs Handles cmdCreateDB.Click ResetScript Dim sDatabaseName As String Input the database name sDatabaseName InputBox Enter the new database name New Database Try Dim oDatabase As New Database oSQLServer sDatabaseName oDatabase.Create Add the DB name to the list lstDatabases.Items.Add oDatabase.Name Catch SQLSMOError End Try End Sub This subroutine begins by declaring a string object called sDatabaseName. The Visual Basic InputBox method is then called to prompt the user to enter a new database name to create and the result is placed into the newly created string sDatabaseName. A new Database object is then instantiated using the current SQL Server instance and sDatabaseName string as parameters. To create the new database on the server the database object s Create method is called. The Create method creates the new database using default property settings however you can also set the database object properties before calling the Create method. Last the list of databases displayed by the SMOSample application is updated with the new name by using the lstDatabases object s Items.Add method to add the name of the new database to the list of databases. Transferring Tables In addition to creating and manipulating databases SMO is capable of creating and managing tables and other databases objects. Using the SMOSample application a user can copy tables in the selected database to another database on the server by clicking the Transfer Tables button. Clicking the Transfer Tables button executes the cmdTransferTables_Click event subroutine that you can see in the following listing. NOTE To use the Transfer utility class functions from a client system the DTS run time needs to be installed on the client system. 470 Microsoft SQL Server 2005 Developer s Guide The code in the cmdTransferTables_Click subroutine shows how the SMO Transfer utility class can be .