Ado.net Connection vs Database Code

Source: Internet
Author: User

Ado.net Connection vs Database Tutorial code

You can use this connection wizard to configure connections to Access database files, ODBC data sources, SQL Server databases, SQL Server Mobile phone version databases, SQL Server database files, Oracle database files, and other databases.
Here we select the Microsoft SQL Server option to connect to the SQL Server database. If we are on a local area network, we can click on the Refresh button in the "Add Connection" interface to see which SQL Server databases are connected to the LAN. You can connect to a database in the following ways:
(1) If the database server to be connected with the developer's machine in the same LAN, you can use the LAN IP address or the computer host name in the LAN;
(2) If you want to connect the database server and the developer's machine is not in the same LAN, then requires that the database server must have a public network IP, we can use the public IP to connect, if the database server and Internet domain name, then use the Internet domain name is also possible.
(3) If the database server to which you are connecting is the same machine as the developer, you can use one of the following ways: "(local)" or "." or "127.0.0.1".

Let's take a look at the database connection code


Server=.sqlexpress;attachdbfilename=|datadirectory|mydbfile.mdf; Database=dbname;trusted_connection=yes;
Data source=.sqlexpress;integrated security=true; Attachdbfilename=|datadirectory|mydb.mdf;user instance=true;


The use of connection, command, DataAdapter, and DataReader objects for SQL Server databases, which have classes in other databases, are essentially the same except for some SQL statements that have different syntax.

The

Connection object
Connection object is also known as a database connection object, and the function of the connection object is to connect to the data source. The base class for all connection objects is the DbConnection class. The
Connection object has two important properties:
ConnectionString: Represents a string that is used to open a SQL Server database;
State: Represents the connection status, with closed and open two states. The
Connection object has two important methods:
Open () method: indicates open database;
Close () method: Indicates that the database is closed.
In actual development many friends often ask the database connection string how to write, in fact, there is a very simple technique, we can find in the Visual Studio 2005 Toolbox data grouping

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.