SMO では、 Information オブジェクト、 Settings オブジェクト、 UserOptions オブジェクト、および Configuration オブジェクトには、Microsoft SQL Server のインスタンスの設定と情報が含まれます。
SQL Server には、インストールされているインスタンスの動作を記述する多数のプロパティがあります。 このプロパティでは、スタートアップ オプション、サーバーの既定値、ファイルとディレクトリ、システムとプロセッサの情報、製品とバージョン、接続情報、メモリ オプション、言語と照合順序の選択、認証モードについて説明します。
SQL Server の構成
Information オブジェクトのプロパティには、プロセッサやプラットフォームなど、SQL Server のインスタンスに関する情報が含まれています。
Settings オブジェクトのプロパティには、SQL Server のインスタンスに関する情報が含まれています。 既定のデータベース ファイルとディレクトリは、メール プロファイルとサーバー アカウントに加えて変更できます。 これらのプロパティは、接続の間保持されます。
UserOptions オブジェクトのプロパティには、算術、ANSI 標準、およびトランザクションに関連する現在の接続の動作に関する情報が含まれています。
Configuration オブジェクトによって表される一連の構成オプションもあります。 これには、 sp_configure
ストアド プロシージャによって変更できるオプションを表す一連のプロパティが含まれています。
優先順位の向上、回復間隔、ネットワーク パケット サイズなどのオプションは、SQL Server のインスタンスのパフォーマンスを制御します。 これらのオプションの多くは動的に変更できますが、場合によっては、SQL Server のインスタンスが再起動されたときに値が最初に構成され、その後変更される場合があります。
すべての構成オプションに Configuration オブジェクト プロパティがあります。 ConfigProperty オブジェクトを使用すると、グローバル構成設定を変更できます。 多くのプロパティには、 ConfigProperty プロパティとしても格納される最大値と最小値があります。 これらのプロパティでは、SQL Server のインスタンスに変更をコミットするために、 Alter メソッドが必要です。
Configuration オブジェクトのすべての構成オプションは、システム管理者が変更する必要があります。
例示
次のコード例では、アプリケーションを作成するために、プログラミング環境、プログラミング テンプレート、およびプログラミング言語を選択する必要があります。 詳細については、「 Visual Studio .NET で Visual Basic SMO プロジェクトを作成する」および「Visual Studio .NETで Visual C# SMO プロジェクトを作成する」を参照してください。
Visual Basic での SQL Server 構成オプションの変更
このコード例では、Visual Basic .NET で構成オプションを更新する方法を示します。 また、指定した構成オプションの最大値と最小値に関する情報も取得して表示します。 最後に、変更が動的に行われたかどうか、または SQL Server のインスタンスが再起動されるまで保存されているかどうかをユーザーに通知します。
Visual Basic での SQL Server 設定の変更
このコード例では、sql Server のインスタンスに関する情報を Information および Settingsに表示し、 Settings プロパティと UserOptionsobject プロパティの設定を変更します。
この例では、 UserOptions オブジェクトと Settings オブジェクトの両方に Alter メソッドがあります。 これらの Alter メソッドは、個別に実行できます。
Visual C での SQL Server 設定の変更#
このコード例では、sql Server のインスタンスに関する情報を Information および Settingsに表示し、 Settings プロパティと UserOptionsobject プロパティの設定を変更します。
この例では、 UserOptions オブジェクトと Settings オブジェクトの両方に Alter メソッドがあります。 これらの Alter メソッドは、個別に実行できます。
//Connect to the local, default instance of SQL Server.
{
Server srv = new Server();
//Display all the configuration options.
foreach (ConfigProperty p in srv.Configuration.Properties)
{
Console.WriteLine(p.DisplayName);
}
Console.WriteLine("There are " + srv.Configuration.Properties.Count.ToString() + " configuration options.");
//Display the maximum and minimum values for ShowAdvancedOptions.
int min = 0;
int max = 0;
min = srv.Configuration.ShowAdvancedOptions.Minimum;
max = srv.Configuration.ShowAdvancedOptions.Maximum;
Console.WriteLine("Minimum and Maximum values are " + min + " and " + max + ".");
//Modify the value of ShowAdvancedOptions and run the Alter method.
srv.Configuration.ShowAdvancedOptions.ConfigValue = 0;
srv.Configuration.Alter();
//Display when the change takes place according to the IsDynamic property.
if (srv.Configuration.ShowAdvancedOptions.IsDynamic == true)
{
Console.WriteLine("Configuration option has been updated.");
}
else
{
Console.WriteLine("Configuration option will be updated when SQL Server is restarted.");
}
}
PowerShell での SQL Server 設定の変更
このコード例では、sql Server のインスタンスに関する情報を Information および Settingsに表示し、 Settings プロパティと UserOptionsobject プロパティの設定を変更します。
この例では、 UserOptions オブジェクトと Settings オブジェクトの両方に Alter メソッドがあります。 これらの Alter メソッドは、個別に実行できます。
# Set the path context to the local, default instance of SQL Server.
CD \sql\localhost\
$srv = Get-Item default
#Display information about the instance of SQL Server in Information and Settings.
"OS Version = " + $srv.Information.OSVersion
"State = "+ $srv.Settings.State.ToString()
#Display information specific to the current user in UserOptions.
"Quoted Identifier support = " + $srv.UserOptions.QuotedIdentifier
#Modify server settings in Settings.
$srv.Settings.LoginMode = [Microsoft.SqlServer.Management.SMO.ServerLoginMode]::Integrated
#Modify settings specific to the current connection in UserOptions.
$srv.UserOptions.AbortOnArithmeticErrors = $true
#Run the Alter method to make the changes on the instance of SQL Server.
$srv.Alter()
PowerShell での SQL Server 構成オプションの変更
このコード例では、Visual Basic .NET で構成オプションを更新する方法を示します。 また、指定した構成オプションの最大値と最小値に関する情報も取得して表示します。 最後に、変更が動的に行われたかどうか、または SQL Server のインスタンスが再起動されるまで保存されているかどうかをユーザーに通知します。
#Get a server object which corresponds to the default instance replace LocalMachine with the physical server
cd \sql\LocalMachine
$svr = Get-Item default
#enumerate its properties
foreach ($Item in $Svr.Configuration.Properties)
{
$Item.DisplayName
}
"There are " + $svr.Configuration.Properties.Count.ToString() + " configuration options."
#Display the maximum and minimum values for ShowAdvancedOptions.
$min = $svr.Configuration.ShowAdvancedOptions.Minimum
$max = $svr.Configuration.ShowAdvancedOptions.Maximum
"Minimum and Maximum values are " + $min.ToString() + " and " + $max.ToString() + "."
#Modify the value of ShowAdvancedOptions and run the Alter method.
$svr.Configuration.ShowAdvancedOptions.ConfigValue = 0
$svr.Configuration.Alter()
#Display when the change takes place according to the IsDynamic property.
If ($svr.Configuration.ShowAdvancedOptions.IsDynamic -eq $true)
{
"Configuration option has been updated."
}
Else
{
"Configuration option will be updated when SQL Server is restarted."
}