mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 17:23:27 -05:00
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
29 lines
1.1 KiB
PowerShell
29 lines
1.1 KiB
PowerShell
<#
|
|
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
|