Aracılığıyla paylaş


Özellikleri ayarlama

Özellikler, nesne hakkında açıklayıcı bilgi depolamak değerlerdir. Örneğin, Microsoft  SQL Serveryapılandırma seçenekleri gösterilir Configurationnesne özellikleri. Özellikleri özellik koleksiyonu kullanarak, doğrudan ya da dolaylı olarak erişilebilir. Özelliklerine doğrudan erişim, aşağıdaki sözdizimini kullanır:

objInstance.PropertyName

Özellik değerini güncellenmiştir veya özellik okuma/yazma erişimi ya da salt okunur erişime sahip bağlı alınabilir. Ayrıca, belirli özellikleri nesne oluşturulmadan önce ayarlamak gereklidir. Daha fazla bilgi için bkz: smo başvuru için belirli nesne.

[!NOT]

Alt nesneler koleksiyonları bir nesne özelliği olarak görünür. Örneğin, TablesKoleksiyon özelliği olan bir Servernesnesini. Daha fazla bilgi için, bkz. Koleksiyonlar kullanma.

Bir nesnenin özelliklerini, Properties derlemesi bir üyesidir. Properties derlemesi, her nesnenin özelliği ile yineleme yapmak için kullanılabilir.

Bazen bir özelliği aşağıdaki nedenlerden dolayı kullanılamaz:

  • Sunucu sürümü özelliği desteklemiyor temsil eden yeni bir özellik erişmeyi deneyin örneğin SQL Servereski bir sürümünü özelliğini SQL Server.

  • Sunucu verileri sağlamaz özelliği, örneğin size gösteren bir özellik erişmeye çalışan bir SQL Serverbileşeni yüklü değil.

Bu durumda alıcı tarafından idare UnknownPropertyExceptionve PropertyCannotBeRetrievedExceptionsmo istisnalar.

Varsayılan başlatma alanlar ayarlama

smo nesne alınırken bir iyileştirme gerçekleştirir. Optimizasyon özellikleri aşağıdaki durumlar arasında otomatik ölçeklendirme tarafından yüklenen sayısını en aza indirir:

  1. Kısmen yüklendi. Bir nesneyi ilk başvurulan özellikleri (ad ve şeması gibi) en az vardır.

  2. Tam dolu. Herhangi bir özellik başvurulduğunda yüklemek hızlı kalan özellikleri başlatılır ve kullanılabilir yapılır.

  3. Bellek kullanımı özellikleri. Lots-in bellek ve varsa kalan kullanılamayan özellikler kullanmak bir Expensiveözellik değeri true (gibi DataSpaceUsage). Bu özellikler yalnızca özellikle başvurulan yüklenir.

Eğer uygulamanız kısmen yüklenmiş durumda sağlanan olanları yanında ekstra özellikler getirmek bu ekstra özellikleri almak için bir sorgu gönderir ve tam yüklü durumuna ölçekler. Bu istemci ve sunucu arasında gereksiz trafik neden olabilir. Daha fazla optimizasyon arama yoluyla elde edilebilir SetDefaultInitFieldsyöntemi. SetDefaultInitFieldsYöntemi sağlar nesnesi başlatıldığında yüklenen özellikler tayini.

SetDefaultInitFieldsYöntemi, davranış uygulama veya o sıfırlanana kadar geri kalanı için yükleme özelliğini ayarlar. Özgün davranışı kullanarak kaydedebilirsiniz GetDefaultInitFieldsyöntemi ve gerektiğinde geri.

Ö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.

Bir özelliği Visual Basic'te ayarlama ve alma

Bu kod örneği almak nasıl gösterir Editionözelliği Informationnesnesi ve nasıl SqlExecutionModesözelliği ConnectionContextözelliği ExecuteSqlüyesi SqlExecutionModestürü numaralanmış.

'Connect to the local, default instance of SQL Server.
Dim srv As Server
srv = New Server
'Get a property.
Console.WriteLine(srv.Information.Version)
'Set a property.
srv.ConnectionContext.SqlExecutionModes = SqlExecutionModes.ExecuteSql

Bir özelliği Visual C# içinde ayarlama ve alma

Bu kod örneği almak nasıl gösterir Editionözelliği Informationnesnesi ve nasıl SqlExecutionModesözelliği ConnectionContextözelliği ExecuteSqlüyesi SqlExecutionModestürü numaralanmış.

{ 
//Connect to the local, default instance of SQL Server. 
Server srv; 
srv = new Server(); 
//Get a property. 
Console.WriteLine(srv.Information.Version); 
//Set a property. 
srv.ConnectionContext.SqlExecutionModes = SqlExecutionModes.ExecuteSql; 
}

{ 
//Connect to the local, default instance of SQL Server. 
Server srv; 
srv = new Server(); 
//Get a property. 
Console.WriteLine(srv.Information.Version); 
//Set a property. 
srv.ConnectionContext.SqlExecutionModes = SqlExecutionModes.ExecuteSql; 
}

Visual Basic'te ayarlama çeşitli özellikler önce bir nesne oluşturulur

Bu kod örneği nasıl doğrudan ayarlanacağını gösterir AnsiNullsStatusözelliği Tableve nasıl oluşturmak ve oluşturduğunuz önce sütunları eklemek için nesne Tablenesnesini.

'Connect to the local, default instance of SQL Server.
Dim srv As Server
srv = New Server
'Create a new table in the AdventureWorks2012 database. 
Dim db As Database
db = srv.Databases("AdventureWorks2012")
Dim tb As Table
'Specify the parent database, table schema and the table name in the constructor.
tb = New Table(db, "Test_Table", "HumanResources")
'Add columns because the table requires columns before it can be created. 
Dim c1 As Column
'Specify the parent table, the column name and data type in the constructor.
c1 = New Column(tb, "ID", DataType.Int)
tb.Columns.Add(c1)
c1.Nullable = False
c1.Identity = True
c1.IdentityIncrement = 1
c1.IdentitySeed = 0
Dim c2 As Column
c2 = New Column(tb, "Name", DataType.NVarChar(100))
c2.Nullable = False
tb.Columns.Add(c2)
tb.AnsiNullsStatus = True
'Create the table on the instance of SQL Server.
tb.Create()

Ayarlama çeşitli özellikler önce bir nesne Visual C# içinde oluşturulur

Bu kod örneği nasıl doğrudan ayarlanacağını gösterir AnsiNullsStatusözelliği Tableve nasıl oluşturmak ve oluşturduğunuz önce sütunları eklemek için nesne Tablenesnesini.

{ 
//Connect to the local, default instance of SQL Server. 
Server srv; 
srv = new Server(); 
//Create a new table in the AdventureWorks2012 database. 
Database db; 
db = srv.Databases("AdventureWorks2012"); 
Table tb; 
//Specify the parent database, table schema, and the table name in the constructor. 
tb = new Table(db, "Test_Table", "HumanResources"); 
//Add columns because the table requires columns before it can be created. 
Column c1; 
//Specify the parent table, the column name, and data type in the constructor. 
c1 = new Column(tb, "ID", DataType.Int); 
tb.Columns.Add(c1); 
c1.Nullable = false; 
c1.Identity = true; 
c1.IdentityIncrement = 1; 
c1.IdentitySeed = 0; 
Column c2; 
c2 = new Column(tb, "Name", DataType.NVarChar(100)); 
c2.Nullable = false; 
tb.Columns.Add(c2); 
tb.AnsiNullsStatus = true; 
//Create the table on the instance of SQL Server. 
tb.Create(); 
}

{ 
//Connect to the local, default instance of SQL Server. 
Server srv; 
srv = new Server(); 
//Create a new table in the AdventureWorks2012 database. 
Database db; 
db = srv.Databases("AdventureWorks2012"); 
Table tb; 
//Specify the parent database, table schema, and the table name in the constructor. 
tb = new Table(db, "Test_Table", "HumanResources"); 
//Add columns because the table requires columns before it can be created. 
Column c1; 
//Specify the parent table, the column name, and data type in the constructor. 
c1 = new Column(tb, "ID", DataType.Int); 
tb.Columns.Add(c1); 
c1.Nullable = false; 
c1.Identity = true; 
c1.IdentityIncrement = 1; 
c1.IdentitySeed = 0; 
Column c2; 
c2 = new Column(tb, "Name", DataType.NVarChar(100)); 
c2.Nullable = false; 
tb.Columns.Add(c2); 
tb.AnsiNullsStatus = true; 
//Create the table on the instance of SQL Server. 
tb.Create(); 
}

Tüm özellikleri Visual Basic nesne yineleme

Bu kod örneği aracılığıyla sırayla dolaşır Propertiestopluluğu StoredProcedurenesne ve bunları görüntüler Visual Studioçıkış ekranı.

Örnekte, Propertynesne getirmifltir kare parantez içinde de olduğundan bir Visual Basicanahtar.

'Connect to the local, default instance of SQL Server.
Dim srv As Server
srv = New Server
'Set properties on the uspGetEmployeeManagers stored procedure on the AdventureWorks2012 database.
Dim db As Database
db = srv.Databases("AdventureWorks2012")
Dim sp As StoredProcedure
sp = db.StoredProcedures("uspGetEmployeeManagers")
sp.AnsiNullsStatus = False
sp.QuotedIdentifierStatus = False
'Iterate through the properties of the stored procedure and display.
'Note the Property object requires [] parentheses to distinguish it from the Visual Basic key word.
Dim p As [Property]
For Each p In sp.Properties
    Console.WriteLine(p.Name & p.Value)
Next

Tüm özellikleri Visual C# nesne yineleme

Bu kod örneği aracılığıyla sırayla dolaşır Propertiestopluluğu StoredProcedurenesne ve bunları görüntüler Visual Studioçıkış ekranı.

{ 
//Connect to the local, default instance of SQL Server. 
Server srv; 
srv = new Server(); 
//Set properties on the uspGetEmployeedManagers stored procedure on the AdventureWorks2012 database. 
Database db; 
db = srv.Databases("AdventureWorks2012"); 
StoredProcedure sp; 
sp = db.StoredProcedures("uspGetEmployeeManagers"); 
sp.AnsiNullsStatus = false; 
sp.QuotedIdentifierStatus = false; 
//Iterate through the properties of the stored procedure and display. 
  Property p; 
  foreach ( p in sp.Properties) { 
    Console.WriteLine(p.Name + p.Value); 
  } 
}

{ 
//Connect to the local, default instance of SQL Server. 
Server srv; 
srv = new Server(); 
//Set properties on the uspGetEmployeedManagers stored procedure on the AdventureWorks2012 database. 
Database db; 
db = srv.Databases("AdventureWorks2012"); 
StoredProcedure sp; 
sp = db.StoredProcedures("uspGetEmployeeManagers"); 
sp.AnsiNullsStatus = false; 
sp.QuotedIdentifierStatus = false; 
//Iterate through the properties of the stored procedure and display. 
  Property p; 
  foreach ( p in sp.Properties) { 
    Console.WriteLine(p.Name + p.Value); 
  } 
}

Varsayılan başlatma alanlar Visual Basic'te ayarlama

Bu kod örneği, nesne özelliklerini smo programda başlatıldı sayısını en aza gösterilmiştir. Sen-si olmak-e dahil etmek using System.Collections.Specialized; ifadesini kullanmak için StringCollectionnesnesini.

SQL Server Profilerörneği gönderilen numara deyimleri karşılaştırmak için kullanılan SQL ServerBu iyileştirme ile.

'Connect to the local, default instance of SQL Server.
Dim srv As Server
srv = New Server
'Reference the AdventureWorks2012 database.
Dim db As Database
db = srv.Databases("AdventureWorks2012")
'Assign the Table object type to a System.Type object variable.
Dim tb As Table
Dim typ As Type
tb = New Table
typ = tb.GetType
'Assign the current default initialization fields for the Table object type to a 
'StringCollection object variable.
Dim sc As StringCollection
sc = srv.GetDefaultInitFields(typ)
'Set the default initialization fields for the Table object type to the CreateDate property.
srv.SetDefaultInitFields(typ, "CreateDate")
'Retrieve the Schema, Name, and CreateDate properties for every table in AdventureWorks2012.
'Note that the improvement in performance can be viewed in SQL Profiler.
For Each tb In db.Tables
    Console.WriteLine(tb.Schema + "." + tb.Name + " " + tb.CreateDate)
Next
'Set the default initialization fields for the Table object type back to the original settings.
srv.SetDefaultInitFields(typ, sc)

Varsayılan başlatma alanlar Visual C# içinde ayarlama

Bu kod örneği, nesne özelliklerini smo programda başlatıldı sayısını en aza gösterilmiştir. Sen-si olmak-e dahil etmek using System.Collections.Specialized; ifadesini kullanmak için StringCollectionnesnesini.

SQL Server Profilerörneği gönderilen numara deyimleri karşılaştırmak için kullanılan SQL ServerBu iyileştirme ile.

{ 
//Connect to the local, default instance of SQL Server. 
Server srv; 
srv = new Server(); 
//Reference the AdventureWorks2012 database. 
Database db; 
db = srv.Databases("AdventureWorks2012"); 
//Assign the Table object type to a System.Type object variable. 
Table tb; 
Type typ; 
tb = new Table(); 
typ = tb.GetType; 
//Assign the current default initialization fields for the Table object type to a 
//StringCollection object variable. 
StringCollection sc; 
sc = srv.GetDefaultInitFields(typ); 
//Set the default initialization fields for the Table object type to the CreateDate property. 
srv.SetDefaultInitFields(typ, "CreateDate"); 
//Retrieve the Schema, Name, and CreateDate properties for every table in AdventureWorks2012. 
   //Note that the improvement in performance can be viewed in SQL Server Profiler. 
foreach ( tb in db.Tables) { 
   Console.WriteLine(tb.Schema + "." + tb.Name + " " + tb.CreateDate); 
} 
//Set the default initialization fields for the Table object type back to the original settings. 
srv.SetDefaultInitFields(typ, sc); 
}

{ 
//Connect to the local, default instance of SQL Server. 
Server srv; 
srv = new Server(); 
//Reference the AdventureWorks2012 database. 
Database db; 
db = srv.Databases("AdventureWorks2012"); 
//Assign the Table object type to a System.Type object variable. 
Table tb; 
Type typ; 
tb = new Table(); 
typ = tb.GetType; 
//Assign the current default initialization fields for the Table object type to a 
//StringCollection object variable. 
StringCollection sc; 
sc = srv.GetDefaultInitFields(typ); 
//Set the default initialization fields for the Table object type to the CreateDate property. 
srv.SetDefaultInitFields(typ, "CreateDate"); 
//Retrieve the Schema, Name, and CreateDate properties for every table in AdventureWorks2012. 
   //Note that the improvement in performance can be viewed in SQL Server Profiler. 
foreach ( tb in db.Tables) { 
   Console.WriteLine(tb.Schema + "." + tb.Name + " " + tb.CreateDate); 
} 
//Set the default initialization fields for the Table object type back to the original settings. 
srv.SetDefaultInitFields(typ, sc); 
}