ASP.net database connection

Source: Internet
Author: User

Let's take a look at the Access database connection and open it:

String strConnection = "Provider = Microsoft. Jet. OleDb.4.0; Data Source = ";

StrConnection + = Server. MapPath ("*. mdb"); // * indicates the database name.

OleDbConnection objConnection = new OleDbConnection (strConnection );

ObjConnection. Open (); dim objConnection as OleDbConnection

ObjConnection = new OleDbConnection ("Provider = Microsoft. Jet. OleDb.4.0; Data Source =" + Server. MapPath ("*. mdb "))

ObjConnection. Open ()

 

Next let's take a look at how SQL SERVER connects to the database and opens it:

String strConnection = "server = database connection; uid = user name; pwd = password; database = database name ";

SqlConnediob objConnection = new SqlCOnnection (strConnection );

ObjConnection. Open (); dim objConnection as SqlConnectiom

ObjConnection = new SqlConnection ("server = database connection; uid = username; pwd = password; database = database name ")

ObjConnection. Open ()

In fact, in most cases, the difference between SQL server and ACCESS is not only the connection statement, but also the difference between other definition statements, namely SQL ×× and OLEDB ××.

In addition, if it is an ACCESS database, the following statements must be included at the beginning of the ASPX file:

<% @ Import Namespace = "System. Data" %>

<% @ Import Namespace = "System. Data. OleDb" %>

For SQL SERVER, the following statements are required:

<% @ Import Namespace = "System. Data" %>

<% @ Import Namespace = "System. Data. SqlClient" %>

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.