SMO에서 SQL Server 구성
SMO에서 개체, InformationSettings 개체, UserOptions 개체 및 Configuration 개체에는 Microsoft SQL Server instance 대한 설정과 정보가 포함됩니다.
SQL Server 설치된 instance 동작을 설명하는 다양한 속성이 있습니다. 이러한 속성은 시작 옵션, 서버 기본값, 파일 및 디렉터리, 시스템 및 프로세서 정보, 제품 및 버전, 연결 정보, 메모리 옵션, 언어 및 데이터 정렬 선택, 인증 모드에 대해 설명합니다.
SQL Server 구성
개체 속성에는 Information 프로세서 및 플랫폼과 같은 SQL Server instance 대한 정보가 포함됩니다.
개체 속성에는 Settings SQL Server instance 대한 정보가 포함됩니다. 기본 데이터베이스 파일 및 디렉터리를 메일 프로필 및 서버 계정과 더불어 수정할 수 있습니다. 이러한 속성은 연결 기간 동안 유지됩니다.
UserOptions 개체 속성은 산술 연산, ANSI 표준 및 트랜잭션과 관련된 현재 연결 동작에 대한 정보를 포함합니다.
Configuration 개체로 표시되는 일련의 구성 옵션도 있습니다. 이 개체는 sp_configure
저장 프로시저로 수정할 수 있는 옵션을 나타내는 일련의 속성을 포함합니다. 우선 순위 향상, 복구 간격 및 네트워크 패킷 크기와같은 옵션은 SQL Server instance 성능을 제어합니다. 이러한 옵션 중 대부분은 동적으로 변경할 수 있지만 경우에 따라 SQL Server instance 다시 시작될 때 값이 먼저 구성되고 변경됩니다.
모든 구성 옵션에는 Configuration 개체 속성이 있습니다. ConfigProperty 개체를 사용하여 전역 구성 설정을 수정할 수 있습니다. 대부분의 속성에는 최대값 및 최소값이 있으며 이것 역시 ConfigProperty 속성으로 저장됩니다. 이러한 속성을 사용하려면 메서드가 Alter 변경 내용을 SQL Server instance 커밋해야 합니다.
Configuration 개체의 모든 구성 옵션은 시스템 관리자가 변경해야 합니다.
예제
다음 코드 예제를 사용하려면 애플리케이션을 만들 프로그래밍 환경, 프로그래밍 템플릿 및 프로그래밍 언어를 선택해야 합니다. 자세한 내용은 Visual Studio .NET에서 Visual Basic SMO 프로젝트 만들기 및 Visual Studio .NET에서 Visual C# SMO 프로젝트 만들기를 참조하세요.
Visual Basic에서 SQL Server 구성 옵션 수정
코드 예제는 Visual Basic .NET에서 구성 옵션을 업데이트하는 방법을 보여 줍니다. 또한 지정된 구성 옵션에 대한 최대값 및 최소값 정보를 검색하고 표시합니다. 마지막으로, 프로그램은 사용자에게 변경 내용이 동적으로 이루어졌는지 또는 SQL Server instance 다시 시작될 때까지 저장되었는지 알려줍니다.
Visual Basic에서 SQL Server 설정 수정
코드 예제에서는 및 의 SQL Server instance Information 대한 정보를 표시하고 및 SettingsUserOptions개체 속성의 Settings 설정을 수정합니다.
이 예에서 UserOptions 개체 및 Settings 개체에는 모두 Alter 메서드가 있습니다. 이들에 대한 Alter 메서드를 개별적으로 실행할 수 있습니다.
Visual C#에서 SQL Server 설정 수정
코드 예제에서는 및 의 SQL Server instance Information 대한 정보를 표시하고 및 SettingsUserOptions개체 속성의 Settings 설정을 수정합니다.
이 예에서 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 instance Information 대한 정보를 표시하고 및 SettingsUserOptions개체 속성의 Settings 설정을 수정합니다.
이 예에서 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 instance 다시 시작될 때까지 저장되었는지 알려줍니다.
#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."
}