1. Code in the front-end aspx
1 <%@ Page Language="C #"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_default" %>2 3 <!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd ">4 5 <HTMLxmlns= "http://www.w3.org/1999/xhtml" >6 <HeadID= "Head1"runat= "Server">7 <title>Configure Access database connections</title>8 </Head>9 <Body>Ten <formID= "Form1"runat= "Server"> One <Div> A </Div> - </form> - </Body> the </HTML>
2. Code in the background. cs file
1 usingSystem;2 usingSystem.Collections.Generic;3 usingsystem.web;4 usingSystem.Web.UI;5 usingSystem.Web.UI.WebControls;6 usingSystem.Configuration;7 usingSystem.Data.OleDb;8 9 Public Partial class_default:system.web.ui.pageTen { One protected voidPage_Load (Objectsender, EventArgs e) A { - stringCon_access = configurationmanager.appsettings["Accesscon"]. ToString ();//Get the database connection string in the configuration file -Response.Write ("aceess Database connection string:"+ con_access);//the output gets the database string information theOleDbConnection Ocon =NewOleDbConnection (configurationmanager.appsettings["Accesscon"]); - Try - { -Ocon.open ();//Open a database connection +Response.Write ("<script>alert (' successful connection ') </script>"); -Ocon.close ();//To close a database connection + } A Catch(Exception ex) at { -Response.Write ("<script>alert ("+ ex. ToString () +") </script>"); - } - } -}
3. Part of the code in Web. config
1 </configSections>2 <appSettings>3 <add key="Accesscon " value="provider=microsoft.jet.oledb.4.0; Data source=| Datadirectory|db_access.mdb"/>4 </appSettings>5 < Connectionstrings/>
003. Connect Access Database code