mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-04 01:25:43 -05:00
Update docs (#200)
This is a documentation-only update so automerging. Please review the commit if there are any follow-ups requested. * Update .gitignore for docfx genertated files * Update documenation (part 1) * Update docs and add some samples * More doc updates
This commit is contained in:
28
docs/samples/smo/PowerShellScript/createxmlshema.ps1
Normal file
28
docs/samples/smo/PowerShellScript/createxmlshema.ps1
Normal file
@@ -0,0 +1,28 @@
|
||||
<#
|
||||
This code example shows how to create an XML schema by using the XmlSchemaCollection object.
|
||||
#>
|
||||
|
||||
#DLL location needs to be specified
|
||||
$pathtodll = ""
|
||||
Add-Type -Path "$pathtodll\Microsoft.SqlServer.Smo.dll"
|
||||
Add-Type -Path "$pathtodll\Microsoft.SqlServer.ConnectionInfo.dll"
|
||||
|
||||
#Connection context need to be specified
|
||||
$srv = New-Object Microsoft.SqlServer.Management.Smo.Server()
|
||||
$srv.ConnectionContext.LoginSecure = $false
|
||||
$srv.ConnectionContext.ServerInstance = "instance_name"
|
||||
$srv.ConnectionContext.Login = "user_id"
|
||||
$srv.ConnectionContext.Password = "pwd"
|
||||
|
||||
#Reference the master database
|
||||
$db = $srv.Databases["master"]
|
||||
|
||||
#Create a new schema collection
|
||||
$xsc = New-Object -TypeName Microsoft.SqlServer.Management.SMO.XmlSchemaCollection -argumentlist $db,"SampleCollection"
|
||||
|
||||
#Add the xml
|
||||
$dq = '"' # the double quote character
|
||||
$xsc.Text = "<schema xmlns=" + $dq + "http://www.w3.org/2001/XMLSchema" + $dq + " xmlns:ns=" + $dq + "http://ns" + $dq + "><element name=" + $dq + "e" + $dq + " type=" + $dq + "dateTime" + $dq + "/></schema>"
|
||||
|
||||
#Create the XML schema collection on the instance of SQL Server.
|
||||
$xsc.Create
|
||||
27
docs/samples/smo/PowerShellScript/dbiteration.ps1
Normal file
27
docs/samples/smo/PowerShellScript/dbiteration.ps1
Normal file
@@ -0,0 +1,27 @@
|
||||
<#
|
||||
This script demonstrates iterations through the rows and display collation details for a remote or local instance of SQL Server.
|
||||
#>
|
||||
|
||||
#DLL location needs to be specified
|
||||
$pathtodll = ""
|
||||
|
||||
Add-Type -Path "$pathtodll\Microsoft.SqlServer.Smo.dll"
|
||||
Add-Type -Path "$pathtodll\Microsoft.SqlServer.ConnectionInfo.dll"
|
||||
|
||||
#Connection context need to be specified
|
||||
$srv = New-Object Microsoft.SqlServer.Management.Smo.Server()
|
||||
$srv.ConnectionContext.LoginSecure = $false
|
||||
$srv.ConnectionContext.ServerInstance = "instance_name"
|
||||
$srv.ConnectionContext.Login = "user_id"
|
||||
$srv.ConnectionContext.Password = "pwd"
|
||||
|
||||
$datatable = $srv.EnumCollations()
|
||||
|
||||
Foreach ($row in $datatable.Rows)
|
||||
{
|
||||
Write-Host "============================================"
|
||||
Foreach ($column in $row.Table.Columns)
|
||||
{
|
||||
Write-Host $column.ColumnName "=" $row[$column].ToString()
|
||||
}
|
||||
}
|
||||
58
docs/samples/smo/PowerShellScript/managetable.ps1
Normal file
58
docs/samples/smo/PowerShellScript/managetable.ps1
Normal file
@@ -0,0 +1,58 @@
|
||||
<#
|
||||
This code example creates a table that has several columns with different types and purposes. The code also provides examples of how to create an identity field, how to create a primary key, and how to alter table properties.
|
||||
#>
|
||||
|
||||
#DLL location needs to be specified
|
||||
$pathtodll = ""
|
||||
Add-Type -Path "$pathtodll\Microsoft.SqlServer.Smo.dll"
|
||||
Add-Type -Path "$pathtodll\Microsoft.SqlServer.ConnectionInfo.dll"
|
||||
|
||||
#Connection context need to be specified
|
||||
$srv = New-Object Microsoft.SqlServer.Management.Smo.Server()
|
||||
$srv.ConnectionContext.LoginSecure = $false
|
||||
$srv.ConnectionContext.ServerInstance = "instance_name"
|
||||
$srv.ConnectionContext.Login = "user_id"
|
||||
$srv.ConnectionContext.Password = "pwd"
|
||||
|
||||
#And the database object corresponding to master.
|
||||
$db = $srv.Databases["master"]
|
||||
|
||||
#Create a SMO Table
|
||||
$tb = New-Object -TypeName Microsoft.SqlServer.Management.SMO.Table -argumentlist $db, "Test_Table"
|
||||
|
||||
#Add various columns to the table.
|
||||
$Type = [Microsoft.SqlServer.Management.SMO.DataType]::NChar(50)
|
||||
$col1 = New-Object -TypeName Microsoft.SqlServer.Management.SMO.Column -argumentlist $tb,"Name", $Type
|
||||
$col1.Collation = "Latin1_General_CI_AS"
|
||||
$col1.Nullable = $true
|
||||
$tb.Columns.Add($col1)
|
||||
|
||||
$Type = [Microsoft.SqlServer.Management.SMO.DataType]::Int
|
||||
$col2 = New-Object -TypeName Microsoft.SqlServer.Management.SMO.Column -argumentlist $tb,"ID", $Type
|
||||
$col2.Identity = $true
|
||||
$col2.IdentitySeed = 1
|
||||
$col2.IdentityIncrement = 1
|
||||
$tb.Columns.Add($col2)
|
||||
|
||||
$Type = [Microsoft.SqlServer.Management.SMO.DataType]::Real
|
||||
$col3 = New-Object -TypeName Microsoft.SqlServer.Management.SMO.Column -argumentlist $tb,"Value", $Type
|
||||
$tb.Columns.Add($col3)
|
||||
|
||||
$Type = [Microsoft.SqlServer.Management.SMO.DataType]::DateTime
|
||||
$col4 = New-Object -TypeName Microsoft.SqlServer.Management.SMO.Column -argumentlist $tb,"Date", $Type
|
||||
$col4.Nullable = $false
|
||||
$tb.Columns.Add($col4)
|
||||
|
||||
#Create the table
|
||||
$tb.Create()
|
||||
|
||||
$Type = [Microsoft.SqlServer.Management.SMO.DataType]::DateTime
|
||||
$col5 = New-Object -TypeName Microsoft.SqlServer.Management.SMO.Column -argumentlist $tb,"ExpiryDate", $Type
|
||||
$col5.Nullable = $false
|
||||
$tb.Columns.Add($col5)
|
||||
|
||||
#Run the Alter method to make the change on the instance of SQL Server.
|
||||
$tb.Alter()
|
||||
|
||||
#Remove the table from the database.
|
||||
$tb.Drop()
|
||||
45
docs/samples/smo/net45/Scripting/Program.cs
Normal file
45
docs/samples/smo/net45/Scripting/Program.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using Microsoft.SqlServer.Management.Smo;
|
||||
using Microsoft.SqlServer.Management.Sdk.Sfc;
|
||||
|
||||
namespace Microsoft.SqlServer.Management.SmoSdkSamples
|
||||
{
|
||||
// This application demonstrates how to script out a sample database without dependencies and iterate through the list to display the results.
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
// Connect to the local, default instance of SQL Server.
|
||||
Smo.Server srv = new Smo.Server();
|
||||
// database name
|
||||
Console.WriteLine("Enter database name for scripting:");
|
||||
string dbName = Console.ReadLine();
|
||||
// Reference the database.
|
||||
Database db = srv.Databases[dbName];
|
||||
// Define a Scripter object and set the required scripting options.
|
||||
Scripter scripter = new Scripter(srv);
|
||||
scripter.Options.ScriptDrops = false;
|
||||
// To include indexes
|
||||
scripter.Options.Indexes = true;
|
||||
// to include referential constraints in the script
|
||||
scripter.Options.DriAllConstraints = true;
|
||||
// Iterate through the tables in database and script each one. Display the script.
|
||||
foreach (Table tb in db.Tables)
|
||||
{
|
||||
// check if the table is not a system table
|
||||
if (tb.IsSystemObject == false)
|
||||
{
|
||||
Console.WriteLine("-- Scripting for table " + tb.Name);
|
||||
// Generating script for table tb
|
||||
System.Collections.Specialized.StringCollection sc = scripter.Script(new Urn[] { tb.Urn });
|
||||
foreach (string st in sc)
|
||||
{
|
||||
Console.WriteLine(st);
|
||||
}
|
||||
Console.WriteLine("--");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
66
docs/samples/smo/net45/Scripting/Scripting.csproj
Normal file
66
docs/samples/smo/net45/Scripting/Scripting.csproj
Normal file
@@ -0,0 +1,66 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{C0CACFBB-FDAF-4B3D-B9F7-EBC3179A5055}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Microsoft.SqlServer.Management.SmoSdkSamples</RootNamespace>
|
||||
<AssemblyName>SmoSdkSamples</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.SqlServer.Management.Sdk.Sfc, Version=14.000.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\SharedManagementObjects.140.1.9\lib\net40\Microsoft.SqlServer.Management.Sdk.Sfc.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.SqlServer.Smo, Version=14.000.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\SharedManagementObjects.140.1.9\lib\net40\Microsoft.SqlServer.Smo.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.SqlServer.SmoExtended, Version=14.000.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\SharedManagementObjects.140.1.9\lib\net40\Microsoft.SqlServer.SmoExtended.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
42
docs/samples/smo/netcore/ModifySetting/Program.cs
Normal file
42
docs/samples/smo/netcore/ModifySetting/Program.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using Microsoft.Data.Tools.DataSets;
|
||||
using Microsoft.SqlServer.Management.Smo;
|
||||
using System;
|
||||
|
||||
namespace Microsoft.SqlServer.Management.SmoSdkSamples
|
||||
{
|
||||
// This example displays information about the instance of SQL Server in Information and Settings, and modifies settings in Settings and UserOptionsobject properties.
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
//Connect to the local, default instance of SQL Server.
|
||||
Microsoft.SqlServer.Management.Smo.Server srv = new Microsoft.SqlServer.Management.Smo.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 = srv.Configuration.ShowAdvancedOptions.Minimum;
|
||||
int max = srv.Configuration.ShowAdvancedOptions.Maximum;
|
||||
Console.WriteLine("Minimum and Maximum values are " + min + " and " + max + ".");
|
||||
int configvalue = srv.Configuration.ShowAdvancedOptions.ConfigValue;
|
||||
//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.");
|
||||
}
|
||||
// Recover setting value
|
||||
srv.Configuration.ShowAdvancedOptions.ConfigValue = configvalue;
|
||||
srv.Configuration.Alter();
|
||||
}
|
||||
}
|
||||
}
|
||||
21
docs/samples/smo/netcore/ModifySetting/project.json
Normal file
21
docs/samples/smo/netcore/ModifySetting/project.json
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"version": "1.0.0-*",
|
||||
"buildOptions": {
|
||||
"debugType": "portable",
|
||||
"emitEntryPoint": true
|
||||
},
|
||||
"dependencies": {
|
||||
"Microsoft.SqlServer.Smo": "140.1.12"
|
||||
},
|
||||
"frameworks": {
|
||||
"netcoreapp1.0": {
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.App": {
|
||||
"type": "platform",
|
||||
"version": "1.0.0"
|
||||
}
|
||||
},
|
||||
"imports": "dnxcore50"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user