VS. NET (C #) upgrade-2.15 _ database interface: several typical connection strings, vs.net

Source: Internet
Author: User

VS. NET (C #) upgrade-2.15 _ database interface: several typical connection strings, vs.net

1) SQL Sever connection string, in two cases: SQL Server Authentication, Windows Integration authentication

① SQLServer Authentication

DataSource= ServerAddress; InitialCatalog= DataBase;UserId= Username;Password= Password;

Or

Server= ServerAddress;Database= DataBase;UserID= Username; Password = Password; Trusted_Connection = False;

Note:

Data Source: The server to be connected.

Note: If the Express version of SQL Server is used, \ SQLEXPRESS must be added after the Server name. For example, to connect to a local SQL Server 2008 Express database Server, you can write Data Source = (local) \ SQLEXPRESS or. \ SQLEXPRESS.

② Windows integration verification

Data Source= ServerAddress;Initial Catalog= DataBase;Integrated Security= SSPI;

Or

Server= MyServerAddress;Database= MyDataBase;Trusted_Connection= True;

Note:

IntegrateSecurity: use an existing windows security certificate to access the database.

2) Access connection string

Provider= Microsoft. Jet. OLEDB.4.0;DataSource= C: \ mydatabase. mdb;UserId= Admin;Password=;

3) MySQL connection string

Server= ServerAddress;Database= DataBase;Uid= Username;Pwd= Password;

4) DB2 connection string

Server= Address: myPortNumber;Database= DataBase;UID= Username;PWD= Password;

5) Oracle connection string

Data Source= TORCL;User Id= Username;Password= Password;

ADO. NET has a special class to process the connection string: DbConnectionStringBuilder class, which generates a base class for strong-type connection strings.

Example

SqlConnectionStringBuilder connstr = new SqlConnectionStringBuilder ();

Connstr. DataSource = @ "(local) \ SQLEXPRESS ";

Connstr. InitialCatalog = "myDataBase ";

Connstr. IntegratedSecurity = true;

Write the connection string in the web. config configuration file Node.

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.