Explanation of common ADO. Net objects: Connection objects

Source: Internet
Author: User
Tags microsoft access database

The connection object can be used to connect to a database to manage database transactions.
1. Create a connection object
Four Database Connection Methods:
Oledb: System. Data. oledb. oledbconnection
SQL: System. Data. sqlcilent. sqlconnection
ODBC: System. Data. ODBC. odbcconnection
Oracle: System. Data. oracleclient. oracleconnection

Let's take a look at an instance created by oledbconnection. There are two methods in total.
First, create an uninitialized oledbconnection object and use connectionstring to initialize it.

Create a connection object
String strconn;
Strconn= "Provider = sqloledb; Data Source = {local) \ netsdk; initial catalog = northwind; trusted_connection = yes;";
Oledbconnection CN;
CN= NewOledbconnection ();
CN. connectionstring=Strconn;

Type 2: Use the constructor to initialize the oledbconnection object. create a connection object

code highlighting produced by actipro codehighlighter (freeware)
http://www.CodeHighlighter.com/

--> string strconn ;< br> strconn = " provider = sqloledb; data Source = {local) \ netsdk; initial catalog = northwind; trusted_connection = yes; " ;< br> oledbconnection CN ;< br> CN = New oledbconnection (strconn) ;

2. connection string
Several common parameters used to connect strings:
Provider: this property is used to set or return to the connection providedProgramIs only used for oledbconnection objects.
Connection timeout or connect Timeout: Wait for the connection time (in seconds) to connect to the server before the attempt is aborted and an exception occurs ). The default value is 15 seconds.
Initail catalog: name of the database.
Data source: the name of the SQL server used when the connection is opened, or the file name of the Microsoft Access database.
Password: the logon password of the SQL Server account.
User ID: The Logon account of SQL Server.
Integrated Security or trusted connection: this parameter determines whether the connection is a secure connection. Possible values include true, false, and sspi (sspi is synonymous with true ).
Persist Security info: when it is set to false, if the connection is opened or has been opened, the security sensitive information (such as the password) will not be returned as part of the connection. Setting the attribute value to true may pose security risks. False is the default value.

3. Open and Close the connection
OpenMethod: Open the connection.
CloseMethod: Close the connection.
Note: If a connection pool is used, closing the connection object will not actually close the connection to the data source.
If you only use dataadapter, you do not need to explicitly open or close the connection. When you call these object methods (fill method, update method), the system automatically checks whether the connection is enabled.

I am so tired -_-!!

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.