Web. config
1
<? XML version =
" 1.0 " Encoding =
" UTF-8 " ?>
<! --
How to configure ASP. NET ApplicationsProgramFor more information, see
HTTP://Go.microsoft.com/fwlink /? Linkid = 169433
-->
<Configuration>
<Deleetask>
<Add key = " Accessconnstring " Value = " Provider = Microsoft. Jet. oledb.4.0; Data Source = " />
<Add key = " Accessdbpath " Value = " ~ /App_data/guestbook. MDB " />
</Appsettings>
<Connectionstrings>
<Add name = " Accessconnectionstring " Connectionstring = " Provider = Microsoft. Jet. oledb.4.0; Data Source = " Providername = " System. Data. oledb " />
<Add name = " Access_path " Connectionstring = " ~ /App_data/guestbook. MDB " />
<Add name = " Sqlconnectionstring " Connectionstring = " Data Source = localhost; initial catalog = guestbook; user id = sa; Password = 123456; " Providername = " System. Data. sqlclient " />
<Add name = " Oracleconnectionstring " Connectionstring = " Data Source = (description = (address_list = (address = (Protocol = TCP) (host = xp2008) (Port = 1521) (CONNECT_DATA = (SID = guandb) (Server = dedicated); User ID = system; Password = k2763826; Unicode = true " Providername = " System. Data. oracleclient " />
</Connectionstrings>
<System. Web>
<Compilation DEBUG = " True " Targetframework = " 4.0 " />
</System. Web>
</Configuration>
2
<? XML version =
" 1.0 " Encoding =
" UTF-8 " ?>
<! --
For more information about how to configure ASP. NET applications, visit
HTTP://Go.microsoft.com/fwlink /? Linkid = 169433
-->
<Configuration>
<Deleetask>
<Add key = " Accessconnstring " Value = " Provider = Microsoft. Jet. oledb.4.0; Data Source = " />
<Add key = " Accessdbpath " Value = " ~ /App_data/guestbook. MDB " />
</Appsettings>
<Connectionstrings>
<Add name = " Accessconnectionstring " Connectionstring =" Provider = Microsoft. Jet. oledb.4.0; Data Source = " />
<Add name = " Access_path " Connectionstring = " ~ /App_data/guestbook. MDB " />
<Add name = " Sqlconnectionstring " Connectionstring =" Data Source = localhost; initial catalog = huarundb; user id = sa; Password = 123456; " Providername = " System. Data. sqlclient " />
</Connectionstrings>
<System. Web>
<Compilation DEBUG = " True " Targetframework = " 4.0 " />
</System. Web>
</Configuration>
Backend Aspx. CS
Using System;
Using System. Collections. Generic;
Using System. LINQ;
Using System. Web;
Using System. Web. UI;
Using System. Web. UI. webcontrols;
Using System. Web. configuration;
Using System. configuration;
Using System. Data. oledb;
Using System. Data;
Namespace Testoracle
{
Public Partial Class Testconnect: system. Web. UI. Page
{
Public Static Readonly String Connstr1 = system. Web. configuration. webconfigurationmanager. connectionstrings [ " Accessconnectionstring " ]. Connectionstring + httpcontext. Current. server. mappath (webconfigurationmanager. connectionstrings [ " Access_path " ]. Connectionstring );
Public Static Readonly String Connstr2 = system. configuration. configurationmanager. appsettings [ " Accessconnstring " ]. Tostring () + system. Web. httpcontext. Current. server. mappath (configurationmanager. etettings [ " Accessdbpath " ]) +" ; " ;
Public Static Readonly String Connstr3 = " Provider = Microsoft. Jet. oledb.4.0; Data Source = " + Httpcontext. Current. server. mappath ( " ~ /App_data/guestbook. MDB " );
Protected Void Page_load ( Object Sender, eventargs E)
{
}
Protected Void Button#click ( Object Sender, eventargs E)
{
Oledbconnection conn = New Oledbconnection (connstr1 );
Try
{
Conn. open ();
String SQL = " Select * From gtcontent " ;
Oledbdataadapter myadapter = New Oledbdataadapter (SQL, Conn );
Dataset DS = New Dataset ();
Myadapter. Fill (DS );
This . Gridview1.datasource = Ds;
This . Gridview1.databind ();
This . Label1.text = " Database Connection successful! " ;
}
Catch (Exception ee)
{
This . Label1.text = ee. tostring ();
}
}
}
}
Connstr1, connstr2, connstr3
Which of the three connection strings can be used.