SQL Server Management Objects (SMO) ApplicationsProgramThe first step is to create a server object instance and create an instance connected to the Microsoft SQL Server.
You can create an instance of the server object and an instance connected to the Microsoft SQL Server in three ways.
The first is to use the serverconnection object variable to Provide link information.
The second is to provide link information by explicitly setting the server object attributes.
The third is to set the name of the SQL server instance in the constructor of the server object.
Use serverconnection object
Using serverconnection object variables is advantageous for reusing link information.
Declare a server object variable. Then declare a serverconnection object, set the attributes of the link information such as the SQL server instance name, and set the Authentication mode. Then, run the serverconnection object as a parameter of the server object constructor. Sharing links are not recommended for different server objects at the same time. Use the copy method to obtain a copy of an existing link setting.
Explicitly set Server Object Attributes
Either. You must declare a server object variable and call the default constructor. Similarly, the server object tries to connect to the default instance of SQL Server with the default link settings.
Provide the SQL server instance name in the server object constructor.
Declare the server object variables and provide the SQL server instance name as a string parameter to call the constructor. The server object establishes a default instance connected to SQL Server with the default link settings.