Reproduced Asp. NET connection string notation Summary

Source: Internet
Author: User

I. Connecting OLE DB data sources using OleDbConnection objects  1. Connect to an Access database
Access 2000:
"Provider=microsoft.jet.oledb.3.5;data source=access file path"
Access 2003:
"Provider=Microsoft.Jet.OLEDB.4.0;Data source=access file path"
Access 2007:
"Provider=microsoft.ace.oledb.12.0;data source=access file path"
Note: Access database provides only two connection properties provider (data Provider) and data source (datasource);
The file format for access2000\2003 is ". MDB ", the file format for Access2007 is". ACCDB ";
The data provider version of Access is backwards-compatible, and testing under WIN7 uses the microsoft.jet.oledb.3.5 hint "the microsoft.jet.oledb.3.5 provider is not registered on the local computer." , use microsoft.jet.oledb.4.0 or microsoft.ace.oledb12.0 to have full access to the Access2000 database file.  Of course, you can also try using MDAC provided by Microsoft to modify the provider version. 2. Connecting to an Excel database
Excel 2003:
"Provider=Microsoft.Jet.OLEDB.4.0;Data source=access file path; extended Properties=excel 8.0"
Excel 2007:
"Provider=microsoft.ace.oledb.12.0;data source=access file path; extended Properties=excel 12.0"
Note: When referencing a worksheet in code, the table name should be expressed as "[sheet name $]", and when the field is reserved for the database, the field name is added [] to differentiate, such as when a SELECT statement is defined: string connstr= "select * FROM [login$] where Username= ' abc ' and [password]= ' abc123 ' ";
If you use numbers as text type data in a datasheet, you should add a single quotation mark before the number to force the default value to the text type. 3. Connecting to the SQL Server database
Provider=sqloledb;
Data source= server name;
Initial catalog= database name;
Uid= users;
pwd= Password Ii. using the SqlConnection object to connect to the SQL Server database
Declaration: The following connected properties can refer to the SQL Server database connection string parameter list for its alias, and other auxiliary properties can be set in addition to the properties that must be set. such as Connect Timeout, encrypt, etc.
To set the database file path:
1. Use absolute path: "Attachdbfilename=d:\\solution1\\web\\app_data\\data.mdf"
2. Using the server-relative path: "Attachdbfilename=" +server.mappath ("\\App_Data\\data.mdf")
3. Use the simplest relative path: "attachdbfilename=| Datadirectory|\\data.mdf "
It is recommended to use the 3rd method, "| Datadirectory| " Represents an automatically created App_Data folder in an ASP.
1. Connecting to SQL Server in the authentication mode
(1) Connect by database name
server= server name;
database= database name;
User id= username;
password= password or (use initials and aliases)
server= server name;
Initial catalog= database name;
Uid= users;
pwd= Password
(2) Complete path to database File connection mode
"Serve= server name; attachdbfilename= database file path; user id= username; password= password"
Example:
server=.\sqlexpress; Database=databasename;
User ID =sa; Password=abc123 "server=.\sqlexpress;
Initial Catalog =databasename; Uid =sa; Pwd=abc123 "
server= (local) \SQLExpress; Attachdbfilename=d:\\solution1\\web\\app_data\\data.mdf; User ID =sa; Password=abc123 "
Note: The password can be empty.
2. Connecting to SQL Server in Windows Authentication mode
(1) Connect by database name
server= server name;
database= database name;
Integrated Security=sspi
(2) Complete path to database File connection mode
"Serve= server name; attachdbfilename= database file path; Integrated security=true"
Example:
server= server name;
database= database name;
Integrated Security=sspi
server= (local) \SQLExpress;
Attachdbfilename=d:\\solution1\\web\\app_data\\data.mdf; Integrated Security=true "
Note: SSPI is true
Iii. connecting an ODBC data source using a OdbcConnection object
"Driver= database provider name; server= server name; database= database name; Trusted_connection=yes"
Example:
First of all, in the Computer Management à data source à configuration of the corresponding data source (select the database type, set the database file path and the corresponding database name)
Driver= microsoft.jet.oledb.4.0;
server=.\sqlexpress;
Database=databasename; Trusted_connection=yes
Iv. using the OracleConnection object to connect to the Oracle database
Data source=oracle8i; Integrated Security=yes
v. Configure the database connection in the Web. config file in the ASP. NET project and get the connection string in the program code
1. Add a connection to the label
Providername= "System.Data.SqlClient"/>
Or
Get the connection string in the tag in the program code:
Reference namespaces:
Using System.Configuration;
String connstr = configurationmanager.connectionstrings["ConnectionName"]. ToString ();
2. Add a connection to the label
Or
Value= "server=.\sqlexpress; attachdbfilename=| datadirectory|\\data.mdf;integrated security=true "/>
Get the connection string in the tag in the program code:
Reference namespaces:
Using System.Configuration;
String connstr = configurationmanager.appsettings["ConnectionName"]. ToString (); This article was reprinted from: http://www.hbxnseo.com/newsview-110.html

Reproduced Asp. NET connection string notation Summary

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.