Connect to an SQL server instance using SMO

Source: Internet
Author: User
Tags sql server management

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.
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.