Aracılığıyla paylaş


Arama yöntemleri

Methods perform specific tasks related to the object, such as issuing a Checkpoint on a database or requesting an enumerated list of logons for the instance of Microsoft SQL Server.

Yöntem, nesne üzerinde bir işlem gerçekleştirin.Yöntem parametre ve genellikle bir dönüş değeri vardır.Dönüş değeri, basit bir veri türü, karmaşık bir nesne veya fazla üye olarak içeren yapısı olabilir.

Özel durum işleme yöntem başarıyla alınmış olup olmadığını algılamak için kullanın.Daha fazla bilgi için bkz:Işleme SMO özel durumlar.

Örnekler

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.

Visual Basic'te bir basit SMO yöntem kullanma

Bu örnekte, Create() yöntem hiçbir parametre ve dönüş değeri yok.

Bir basit SMO yöntem Visual C# ile kullanma

Bu örnekte, Create() yöntem hiçbir parametre ve dönüş değeri yok.

{ 
//Connect to the local, default instance of SQL Server. 
Server srv; 
srv = new Server(); 
//Define a Database object variable by supplying the parent server and the database name arguments in the constructor. 
Database db; 
db = new Database(srv, "Test_SMO_Database"); 
//Call the Create method to create the database on the instance of SQL Server. 
db.Create(); 

}

Bir Parameter Visual Basic'te bir SMO yöntem kullanma

The Table object has a yöntem called RebuildIndexes(Int32). Bu yöntem belirten sayısal bir parametre gerektiriyor FillFactor.

Dim srv As Server
srv = New Server
Dim tb As Table
tb = srv.Databases("AdventureWorks").Tables("Employee", "HumanResources")
tb.RebuildIndexes(70)

Bir Parameter Visual C# ile bir SMO yöntem kullanma

The Table object has a yöntem called RebuildIndexes(Int32). Bu yöntem belirten sayısal bir parametre gerektiriyor FillFactor.

{ 
Server srv = default(Server); 
srv = new Server(); 
Table tb = default(Table); 
tb = srv.Databases("AdventureWorks").Tables("Employee", "HumanResources"); 
tb.RebuildIndexes(70); 
} 

Visual Basic'te bir DataTable nesne döndürüyor bir numaralandırma yöntem kullanma

Bu bölümde bir sıralama yöntem ve döndürülen verileri işlemeye anlatılmaktadır DataTable nesne.

The EnumCollations() yöntem returns a DataTable object, which requires further navigation to access all available harmanlama information about the örnek of SQL Server.

'Connect to the local, default instance of SQL Server.
Dim srv As Server
srv = New Server
'Call the EnumCollations method and return collation information to DataTable variable.
Dim d As DataTable
'Select the returned data into an array of DataRow.
d = srv.EnumCollations
'Iterate through the rows and display collation details for the instance of SQL Server.
Dim r As DataRow
Dim c As DataColumn
For Each r In d.Rows
    Console.WriteLine("============================================")
    For Each c In r.Table.Columns
        Console.WriteLine(c.ColumnName + " = " + r(c).ToString)
    Next
Next

Bir DataTable nesne Visual C# [NULL]'döndürüyor bir numaralandırma yöntem kullanma

Bu bölümde bir sıralama yöntem ve döndürülen verileri işlemeye anlatılmaktadır DataTable nesne.

The EnumCollations() yöntem returns a system DataTable object. The DataTable object requires further navigation to access all available harmanlama information about the örnek of SQL Server.

//Connect to the local, default instance of SQL Server. 
{ 
Server srv = default(Server); 
srv = new Server(); 
//Call the EnumCollations method and return collation information to DataTable variable. 
DataTable d = default(DataTable); 
//Select the returned data into an array of DataRow. 
d = srv.EnumCollations; 
//Iterate through the rows and display collation details for the instance of SQL Server. 
DataRow r = default(DataRow); 
DataColumn c = default(DataColumn); 
foreach ( r in d.Rows) { 
  Console.WriteLine("====================================="); 
  foreach ( c in r.Table.Columns) { 
    Console.WriteLine(c.ColumnName + " = " + r(c).ToString); 
  } 
} 
} 

Visual Basic'te bir nesne oluşturma

Herhangi bir nesnenin oluşturucu kullanılarak çağrılabilir New işleç. The Database object constructor is overloaded and the sürüm of the Database object constructor that is used in the sample takes two parameters: üst Server hangi veritabanı nesnesine ait olduğunu ve yeni veritabanının adını gösteren bir dize.

Bir Visual C# nesne oluşturma

Herhangi bir nesnenin oluşturucu kullanılarak çağrılabilir New işleç. The Database object constructor is overloaded and the sürüm of the Database object constructor that is used in the sample takes two parameters: üst Server hangi veritabanı nesnesine ait olduğunu ve yeni veritabanının adını gösteren bir dize.

{ 
Server srv; 
srv = new Server(); 
Table tb; 
tb = srv.Databases("AdventureWorks").Tables("Employee", "HumanResources"); 
tb.RebuildIndexes(70); 
//Connect to the local, default instance of SQL Server. 
Server srv; 
srv = new Server(); 
//Declare and define a Database object by supplying the parent server and the database name arguments in the constructor. 
Database d; 
d = new Database(srv, "Test_SMO_Database"); 
//Create the database on the instance of SQL Server. 
d.Create(); 
Console.WriteLine(d.Name); 
}

Visual Basic'te SMO nesne kopyalama

Bu kod örneği kullanan Copy() yöntem bir kopyasını oluşturmak için Server nesne. The Server object represents a connection to an örnek of SQL Server.

Visual C# [NULL]'SMO nesne kopyalama

Bu kod örneği kullanan Copy() yöntem bir kopyasını oluşturmak için Server nesne. The Server object represents a connection to an örnek of SQL Server.

{ 
//Connect to the local, default instance of SQL Server. 
Server srv1; 
srv1 = new Server(); 
//Modify the default database and the timeout period for the connection. 
srv1.ConnectionContext.DatabaseName = "AdventureWorks"; 
srv1.ConnectionContext.ConnectTimeout = 30; 
//Make a second connection using a copy of the ConnectionContext property and verify settings. 
Server srv2; 
srv2 = new Server(srv1.ConnectionContext.Copy); 
Console.WriteLine(srv2.ConnectionContext.ConnectTimeout.ToString); 
}

Visual Basic'te sunucu işlemlerini izleme

örnek geçerli durumu türü bilgi alabilirsiniz. SQL Server Sıralama yöntemleri. Kod örneği kullanan EnumProcesses() Geçerli işlemler hakkında bilgi bulmak için yöntem. Nasıl yapılır: çalışmak döndürülen satırları ve sütunları gösterir... DataTable nesne.

Visual C# sunucu işlemlerini izleme

örnek geçerli durumu türü bilgi alabilirsiniz. SQL Server Sıralama yöntemleri. Kod örneği kullanan EnumProcesses() Geçerli işlemler hakkında bilgi bulmak için yöntem. Nasıl yapılır: çalışmak döndürülen satırları ve sütunları gösterir... DataTable nesne.

//Connect to the local, default instance of SQL Server. 
{ 
Server srv = default(Server); 
srv = new Server(); 
//Call the EnumCollations method and return collation information to DataTable variable. 
DataTable d = default(DataTable); 
//Select the returned data into an array of DataRow. 
d = srv.EnumProcesses; 
//Iterate through the rows and display collation details for the instance of SQL Server. 
DataRow r = default(DataRow); 
DataColumn c = default(DataColumn); 
foreach ( r in d.Rows) { 
  Console.WriteLine("================================="); 
  foreach ( c in r.Table.Columns) { 
    Console.WriteLine(c.ColumnName + " = " + r(c).ToString); 
  } 
} 
} 

See Also

Reference

Server

ServerConnection