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.