# Region connection string
The connection string contains 2
1 absolute path
String strcon = @ "provider = Microsoft. jet. oledb.4.0; Data Source = D: \ Program book SOFTWARE \ C # program code \ Access database operation \ Addresslist. mdb "; // absolute path
2 relative path, where environment. currentdirectory is the execution path of the program exe.
String strcon = @ "provider = Microsoft. Jet. oledb.4.0; Data Source =" + environment. currentdirectory + "\ Addresslist. mdb"; // relative path
3app. config
String strcon = configurationmanager. deleettings ["addaccess"]. tostring (); // method 3: Use the app. config file to add references and add using.
Bytes ------------------------------------------------------------------------------------
App
<? XML version = "1.0" encoding = "UTF-8"?>
<Configuration>
<Connectionstrings>
<! -- SQL2000 connection string -->
<Add name = "consql" connectionstring = "Data Source = localhost; database = fuxiaojun; uid = sa; Pwd = ruheshi0372"
Providername = "system. Data. sqlclient"/>
</Connectionstrings>
<Deleetask>
<! -- SQL2000 connection string -->
<! -- <Add key = "testaddsql2000"
Value = "Server = localhost; database = fuxiaojun; user id = sa; Password = ruheshi0372"/> -->
<! -- Access connection string -->
<Add key = "addaccess"
Value = "provider = Microsoft. Jet. oledb.4.0; Data Source = D: \ Program book SOFTWARE \ C # program code \ Access database operation \ Addresslist. mdb"/>
<! -- Access relative path data source = | datadirectory | \ database. mdb database is stored in the app_data folder -->
<Add name = "acccnstr" connectionstring = "provider = Microsoft. jet. oledb.4.0; Data Source = | datadirectory | \ date. MDB; persist Security info = true "providername =" system. data. oledb "/>
</Appsettings>
</Configuration>
Call
-
C # code
-
String connstr = configurationmanager. connectionstrings ["connstr"]. tostring ();
Oledbconnection conn = new oledbconnection (connstr );