ASP. Net connection SQL server connection string, asp. netsqlserver

Source: Internet
Author: User
Tags sql server connection string

ASP. Net connection SQL server connection string, asp. netsqlserver

  • Reference namespace
1      using   System.Data;   2      using   System.Data.SqlClient;  

 

  • Connection string
1 // windows Authentication mode the database contains a single instance. 2 string connectionString = "Data Source = localhost; Initial Catalog = Northwind; Integrated Security = SSPI; "3 // multi-instance 4 string connectionString =" Data Source = localhost \ SQLEXPRESS; Initial Catalog = Northwind; Integrated Security = True; "5 // SQL Server Verification Method = Data Source = 127.0.0.1 can be connected to the local database 6 string connectionString =" Data Source = 10.1.2.3; Initial Catalog = Northwind; User ID = sa; password = abc123 ";

"Integrated Security = SSPI;" & "Integrated Security = True;" it is equivalent to setting Integrated Security to SSPI or True, that is, use the current Windows Account creden。 for authentication. However, in the ASP. NET program, the current running host environment may be different, and the user to which it points will be different.

① Use ASP in Windows Xp. NET account; ② use the NetWork Service account in Windows 2003 and later; ③ use the user account in the current development environment in Visual Studio, not ASP.. NET account.
When aspnet connects to sql2005, where do I enter the database connection string?

In the web. config configuration file
Add
<ConnectionStrings>
<Add name = "B2CCon" connectionString = "server =. \ SQLexpression; database = name of the database to be connected; integrated security = true"/>
</ConnectionStrings>

How can I use Aspnet to connect to a database if I have only installed windows?

Only local connections are allowed. passwords and users are not set in the connection string. Instead, Integrated Security = true is used;

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.