C # database connection string set

Source: Internet
Author: User
Tags odbc connection

C # database connection string set
(1) Common connections:
1. Use the sqlconnection object:

A. SQL Verification
Public void sqlconnectionopen ()
{
Sqlconnection conn = new sqlconnection ();
Conn. connectionstring = "User ID = sa; Password =; initial catalog = northwind; datasource = localhost; Connect timeout = 20 ";
Conn. open ();
}

B. Windows Authentication

Public void sqlconnectionopen ()
{
Sqlconnection conn = new sqlconnection ();
Conn. connectionstring = "Integrated Security = sspi; initial catalog = northwind; datasource = localhost; Connect timeout = 20 ";
Conn. open ();
}

2. Use oledbconnection object:
Public void oledbconnectionopen ()
{
Oledbconnection conn = new oledbconnection ();
Conn. connectionstring = "provider = Microsoft. Jet. oledb.4.0; datasource = C:/customer. mdb ";
Conn. open ();
}
(2) Others:
1. ODBC connection to access local database
Congoodday. Open ("driver = {Microsoft Access Driver (*. mdb)};" + "DBQ = C:/a. mdb;" +
"Uid = admin;" + "Pwd = ;");
2. ODBC connection to the Access System Database
Congoodday. Open ("driver = {Microsoft Access Driver (*. mdb)};" + "DBQ = C:/a. mdb;" +
"Systemdb = admin;" + "Pwd = ;");
3. ODBC connection to the Access System Database
Congoodday. Open ("driver = {Microsoft Access Driver (*. mdb)};" + "DBQ = // server/share/a. mdb ;");
4. ODBC connection to the Excel System Database
Congoodday. Open ("driver = {Microsoft Access Driver (*. xls)};" + "driverid = 790;" +
"DBQ = C:/a.xls;" + "defaultdir = C:/somepath ;");
5. Connecting ODBC to the Oracle database
Congoodday. Open ("driver = {Microsoft ODBC for Oracle};" + "Server = oracleserver. World;" +
"Uid = admin;" + "Pwd = password ;");
6. ODBC connection SQL servr
Congoodday. Open ("driver = {SQL Server};" + "Server = myserver;" + "database = mydatabasename ;"
"Uid = admin;" + "Pwd = password ;");
7. ODBC connection to Visual FoxPro
Congoodday. Open ("driver = {Microsoft Visual FoxPro driver};" +
"Sourcetype = dBc;" + "sourcedb = C: A. dBc;" + "exclusive = no ;");

 

 

Windows Authentication

We recommend that you use Windows authentication (sometimes referred to as "Integrated Security") to connect to a data source that supports it. The syntax used in the connection string varies with the provider. The following table demonstrates the Windows Authentication syntax for. NET Framework data providers.

Providers
Syntax
 
Sqlclient
Integrated Security = true;

-- Or --

Integrated Security = sspi;
 
Oledb
Integrated Security = sspi;
 
ODBC
Trusted_connection = yes;
 
Oracleclient
Integrated Security = yes;
 

When integrated security = true is used for oledb providers, an exception is thrown.

 

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/farawayplace613/archive/2009/01/24/3852104.aspx

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.