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

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

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

 

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.

Product Spotlight
Product Spotlight 
Learn More
.NET Tools
asp.net shopping cart
asp.net chart control






Ads Powered by Lake Quincy Media
Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2008 ASPAlliance.com  |  Page Processed at 7/19/2008 10:31:40 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search