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