The resource has not been reviewed by Editors yet. Readers are advised to use their best judgement before accessing this resource. This resource will be reviewed shortly. If you think this resource contain inappropriate content, please report to webmaster. |
SMO is used for database administration for SQLSERVER 2005.
SQL Server 2000 supports a COM-based object model, called SQL-DMO, which can be used to programmatically manage the SQL Servers. Enterprise Manager uses this API to manage SQL Server. SQL Server 2005 replaces SQL-DMO
The import name spaces assemblies for using SMO are
1.Microsoft.SqlServer.Management.Smo
2.Microsoft.SqlServer.Management.Smo.Agent
3.Microsoft.SqlServer.Management.Smo.Broker
4.Microsoft.SqlServer.Management.Smo.Mail
5.Microsoft.SqlServer.Management.Smo.RegisteredServers
6.Microsoft.SqlServer.Management.Smo.Wmi
#####################################################################
#
# CLOSE AND DISCONNECT AN SMO OBJECT IN IRONPYTHON
#
#
######################################################################
import sys
import clr
sys.path.append(r"D:\Program Files\Microsoft SQL Server\90\SDK\Assemblies")
clr.AddReferenceToFile('Microsoft.SqlServer.Smo.dll')
#clr.AddReferenceToFile('Microsoft.SqlServer.SmoEnum.dll')
#clr.AddReferenceToFile('Microsoft.SqlServer.SqlEnum.dll')
clr.AddReferenceToFile('Microsoft.SqlServer.ConnectionInfo.dll')
from Microsoft.SqlServer.Management.Smo import *
from Microsoft.SqlServer.Management.Common import *
import Microsoft.SqlServer.Management.Smo as SMO
import Microsoft.SqlServer.Management.Common as Common
#
#
#connect to the sqlserver with IP adress, login, password
#NOTE : IPADDRESS,LOGIN,PASSWORD IN THIS EXAMPLE INTENTIONALLY MARKED AS xx
#
#
srv = SMO.Server("XXX.XX.XX.XX")
srv.ConnectionContext.LoginSecure = 0
srv.ConnectionContext.Login = "xx"
srv.ConnectionContext.Password = "xx"
#Disable automatic disconnection.
srv.ConnectionContext.AutoDisconnectMode = AutoDisconnectMode.NoAutoDisconnect
#Connect to the local, default instance of SQL Server.
srv.ConnectionContext.Connect()
#The actual connection is made when a property is retrieved.
print srv.Information.Version
#Disconnect explicitly.
srv.ConnectionContext.Disconnect()