Retrieving Database Schema Information using the OleDbSchemaGuid Class
page 2 of 4
by Steven Swafford
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 26128/ 42

Establish a Connection to the Access Database

In this article we will create a Web form that retrieves and displays schema information from an Access database.

The first step to establish a connection to the Access database. In this case I am using xtreme.mdb, a sample database with the Visual Studio .NET 2003 installation. (This database is included in the code sample download.)

Figure 1: Establish a Connection to the Access Database

// Estblish connection string
public static readonly string STRCONN = "Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=D:\\Dot Net\\ASPAlliance\\Article631\\xtreme.mdb;"; 
// Establish the OleDb connection to your access database
OleDbConnection oleDbConn = new OleDbConnection(STRCONN);


If you do not like the idea of storing the database connection string within your code, you can instead retrieve it from the Web.config configuration file.

Figure 2: Store Database Connection String within Web.config

    <add key=”ConnectionString” value=” Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=D:\\Dot Net\\ASPAlliance\\Article631\\xtreme.mdb;” />


We use the following code to retrieve the database connection string from the Web.config file:

Figure 3: Retrieve the Database Connection String

using System.Configuration;
string strConn = (string)ConfigurationSettings.AppSettings[“ConnectionString”];


View Entire Article

User Comments

No comments posted yet.

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2024  |  Page Processed at 2024-04-15 2:20:19 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search