SQL Server connection string records

Source: Internet
Author: User
Tags sql server connection string connectionstrings

In general, we will configure the relevant connection string in the web. config file, which is recorded here for future use.

1. Commonly Used <connectionstrings> nodes

A: SQL Server Authentication connection string

View code

1 <connectionstrings>
2 <Add name = "connectionstringname" connectionstring = "Server =.; database = database name; uid = username; Pwd = password ;"
3 providername = "system. Data. sqlclient"> </Add>
4 </connectionstrings>

B. Windows Authentication connection string

View code

1 <connectionstrings>
2 <Add name = "connectionstringname" connectionstring = "Data Source = server name; initial catalog = database name; Integrated Security = sspi ;"
3 providername = "system. Data. sqlclient"> </Add>
4 </connectionstrings>

In addition, you can use <connectionstrings configsource = "configration \ connectionstring. config"/> to specify the definition in an external file.

Code: see the above.

Method for obtaining connectionstring: system. configuration. configurationmanager. connectionstrings ["connectionstringname"]. connectionstring;

2. Configure the node in <etettings> (for Windows verification, refer to 1. B)

View code

1 <deleetask>
2 <add key = "connectionstringname" value = "Server =.; database = database name; uid = username; Pwd = password;"/>
3 </appsettings>

Method for obtaining connectionstring: system. configuration. configurationmanager. deleetpipeline ["connectionstringname"]. tostring ();

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.