Aracılığıyla paylaş


Arama yöntemleri

Yöntemleri verme gibi nesneye ilgili belirli görevleri gerçekleştirmek bir Checkpointbir veritabanı veya numaralandırılmış bir liste örneği için oturum açma isteğinde Microsoft   SQL Server.

Yöntem bir nesne üzerinde bir işlem gerçekleştirin. Yöntem parametreleri almak ve genellikle dönüş değeri vardır. Dönüş değeri, basit veri türüne, karmaşık bir nesne ya da çok sayıda üye içeren bir yapı olabilir.

Özel durum işleme yönteminin başarılı olup olmadığını algılamak için kullanın. 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 bir basit smo yöntemini kullanma

Bu örnekte, Createyöntemi parametre alır ve dönüş değeri yok.

'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()

Basit smo yöntemini Visual C# içinde kullanarak

Bu örnekte, Createyöntemi parametre alır 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(); 

{ 
//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

TableNesnesi adında bir yöntemi vardır RebuildIndexes. Bu yöntem belirten sayısal parametre gerektirir FillFactor.

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

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

Bir parametre Visual C# ile bir smo yöntemini kullanma

TableNesnesi adında bir yöntemi vardır RebuildIndexes. Bu yöntem belirten sayısal parametre gerektirir FillFactor.

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

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

Visual Basic'te bir DataTable nesnesi döndüren bir Enumeration yöntemini kullanma

Bu bölümde bir enumeration yöntemini çağırın ve döndürülen verileri işlemek üzere nasıl açıklar DataTablenesnesini.

EnumCollationsYöntemi döner bir DataTablenesnesi, tüm kullanılabilir harmanlama bilgileri örneği erişmek için Gezinti daha fazla gerektirir 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

'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# içinde döndürüyor bir Enumeration yöntemini kullanma

Bu bölümde bir enumeration yöntemini çağırın ve döndürülen verileri işlemek üzere nasıl açıklar DataTablenesnesini.

EnumCollationsYöntemi bir sistem döner DataTablenesnesini. DataTableTüm kullanılabilir harmanlama bilgileri örneği erişmek için daha fazla gezinti nesnesi gerektirir 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); 
  } 
} 
} 

//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 nesne yapıcısı kullanılarak çağrılabilir Newoperatör. DatabaseNesne yapıcısı aşırı ve Databaseörnekte kullanılan nesne Oluşturucu iki parametre alır: Ana Serverait olduğu veritabanı nesnesi ve yeni veritabanının adını temsil eden bir dize.

'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# bir nesne oluşturma

Herhangi bir nesne yapıcısı kullanılarak çağrılabilir Newoperatör. DatabaseNesne yapıcısı aşırı ve Databaseörnekte kullanılan nesne Oluşturucu iki parametre alır: Ana Serverait olduğu veritabanı nesnesi ve yeni veritabanının adını temsil eden bir dize.

{ 
Server srv; 
srv = new Server(); 
Table tb; 
tb = srv.Databases("AdventureWorks2012").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); 
}

{ 
Server srv; 
srv = new Server(); 
Table tb; 
tb = srv.Databases("AdventureWorks2012").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 Copyyöntemi bir kopyasını oluşturmak için Servernesnesini. ServerNesnesinin bir örneğini bir bağlantıyı temsil eden 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 = "AdventureWorks2012"
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 Copyyöntemi bir kopyasını oluşturmak için Servernesnesini. ServerNesnesinin bir örneğini bir bağlantıyı temsil eden 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 = "AdventureWorks2012"; 
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); 
}

{ 
//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 = "AdventureWorks2012"; 
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

Örneği geçerli durum türü bilgilerini edinebilir SQL Serverüzerinden numaralandırma yöntemleri. Kod örneği kullanır EnumProcessesyöntemi geçerli işlemler hakkında bilgi bulmak için. O da iş döndürülen satır ve sütunlar ile gösterilmiştir DataTablenesnesini.

'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# süreçlerin izlenmesi

Örneği geçerli durum türü bilgilerini edinebilir SQL Serverüzerinden numaralandırma yöntemleri. Kod örneği kullanır EnumProcessesyöntemi geçerli işlemler hakkında bilgi bulmak için. O da iş döndürülen satır ve sütunlar ile gösterilmiştir DataTablenesnesini.

//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); 
  } 
} 
} 

//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

Server

ServerConnection