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 bir nesne üzerinde bir işlem gerçekleştirin.Yöntem parametreleri alýp genellikle dönüş değeri vardır.Dönüş değeri, bir basit veri türü, karmaşık bir nesne veya çok sayıda üye içeren bir yapı olabilir.

Özel durum işleme algılamak için kullanın olup olmadığını yöntem başarılı olmuştur.Daha fazla bilgi için bkz: smo özel durumları.

Örnekler

Sunulan kod örneklerinden herhangi birini kullanmak için, programlama ortamını, programlama şablonunu ve uygulamanızı oluşturacağınız programlama dilini seçmeniz gerekecektir. Daha fazla bilgi için SQL Server Boks Online'da "How to: Create a Visual Basic SMO Project in Visual Studio .NET" (Nasıl Yapılır: Visual Studio .NET içinde Visual Basic SMO Projesi Oluşturma) veya "How to: Create a Visual C# SMO Project in Visual Studio .NET" (Nasıl Yapılır: Visual Studio .NET içinde Visual C# SMO Projesi Oluşturma) konularına bakın.

Visual Basic'te basit smo yöntemini kullanma

Bu örnekte, Create yöntem parametre alır ve var. hiçbir dönüş değeri

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

Visual C# [NULL]'ta basit smo yöntemini kullanma

Bu örnekte, Create yöntem parametre alır ve var. hiçbir dönüş değeri

{ 
//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(); 

}

Visual Basic'te bir parametre ile bir smo yöntemini kullanma

The Table object has a method called RebuildIndexes.Bu yöntem belirten bir sayısal parametre gerektirir FillFactor.

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

Visual C# içinde bir parametre ile bir smo yöntemini kullanma

The Table object has a method called RebuildIndexes.Bu yöntem belirten bir sayısal parametre gerektirir FillFactor.

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

Visual Basic'te bir DataTable nesnesi döndüren bir numaralandırma yöntemi kullanma

Bu bölüm numaralandırma yöntem çağırmak ve döndürülen verileri işlemek anlatılmaktadır DataTable nesne.

The EnumCollations method returns a DataTable object, which requires further navigation to access all available collation information about the instance 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

Visual C# içinde bir DataTable nesnesi döndüren bir numaralandırma yöntemi kullanma

Bu bölüm numaralandırma yöntem çağırmak ve döndürülen verileri işlemek anlatılmaktadır DataTable nesne.

The EnumCollations method returns a system DataTable object.The DataTable object requires further navigation to access all available collation information about the instance 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 yapıcısını kullanarak çağrılabilir New işleç.The Database object constructor is overloaded and the version of the Database object constructor that is used in the sample takes two parameters: Ana Server nesnesinin ait olduğu veritabanının olduğu ve adını temsil eden bir dizeyeni veritabanı.

'Connect to the local, default instance of SQL Server.
Dim srv As Server
srv = New Server
'Declare and define a Database object by supplying the parent server and the database name arguments in the constructor.
Dim d As Database
d = New Database(srv, "Test_SMO_Database")
'Create the database on the instance of SQL Server.
d.Create()
Console.WriteLine(d.Name)

Visual C# içinde bir nesne oluşturma

Herhangi bir nesnenin yapıcısını kullanarak çağrılabilir New işleç.The Database object constructor is overloaded and the version of the Database object constructor that is used in the sample takes two parameters: Ana Server nesnesinin ait olduğu veritabanının olduğu ve adını temsil eden bir dizeyeni veritabanı.

{ 
Server srv; 
srv = new Server(); 
Table tb; 
tb = srv.Databases("AdventureWorks2008R2").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 kullanır Copy yöntem bir kopyasını oluşturmak için Server nesne.The Server object represents a connection to an instance of SQL Server.

'Connect to the local, default instance of SQL Server.
Dim srv1 As Server
srv1 = New Server()
'Modify the default database and the timeout period for the connection.
srv1.ConnectionContext.DatabaseName = "AdventureWorks2008R2"
srv1.ConnectionContext.ConnectTimeout = 30
'Make a second connection using a copy of the ConnectionContext property and verify settings.
Dim srv2 As Server
srv2 = New Server(srv1.ConnectionContext.Copy)
Console.WriteLine(srv2.ConnectionContext.ConnectTimeout.ToString)

smo nesne Visual C# içinde kopyalama

Bu kod örneği kullanır Copy yöntem bir kopyasını oluşturmak için Server nesne.The Server object represents a connection to an instance 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 = "AdventureWorks2008R2"; 
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 Server işlemler izleme

örnek geçerli durum türü bilgi edinebilirsiniz SQL Server üzerinden numaralandırma yöntemleri.Kod örneği kullanır EnumProcesses yöntem hakkında bilgi bulmak içingeçerli işlemler. Bunu aynı zamanda sütun ve satır döndürülen çalışmak gösterilmiştir DataTable nesne.

'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.EnumProcesses
'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

Visual C# [NULL]'taki Server işlemler izleme

örnek geçerli durum türü bilgi edinebilirsiniz SQL Server üzerinden numaralandırma yöntemleri.Kod örneği kullanır EnumProcesses yöntem hakkında bilgi bulmak içingeçerli işlemler. Bunu aynı zamanda sütun ve satır döndürülen çalışmak gösterilmiştir 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); 
  } 
} 
} 

Ayrıca bkz.

Başvuru