ASP.Net C# access database

by top54u.com 13 Feb, 2008

ASP.Net C# syntax for Access database:

Ms Access Database connection string for OLEDB Provider:


 

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("PATH OF MS ACCESS DATABASE FILE");

 

OLEDB (Object Linking and Embedding Database Drivers Provider)
Place your Ms Access Database file inside the default App_Data Folder of ASP.Net 2.0
Then you can use the Server.MapPath(“App_Data/db.mdb”) to provide the file path of access database. You can host your database directly into App_Data folder while you are hosting your ASP.Net 2.0 web application on the web server.

Import Namespaces for Oledb: 

using System.Data;
using System.Data.OleDb;

 

See the C# Source code below for ASP.Net 2.0 connection to access database:

 

// Access Database oledb connection string
// Using Provider Microsoft.Jet.OLEDB.4.0
string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("../App_Data/db1.mdb");

 

// Object created for Oledb Connection
OleDbConnection myAccessConnection = new OleDbConnection(connStr);

 

// If condition that can be used to check the access database connection
// whether it is already open or not.
if (myAccessConnection.State == ConnectionState.Closed)
{
    myAccessConnection.Open();
}

 

// Message that displays the access database connection state
Response.Write("ASP.Net Access Database Connection State: <b>" + myAccessConnection.State + "</b>");

 

// If condition to check the access database connection state
// If it is open then close it.
if (myAccessConnection.State == ConnectionState.Open)
{
    myAccessConnection.Close();
}

 

 

Spotlight.....

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

Comments

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

10/11/2008 3:25:50 AM




related videos.....
recent posts.....
top54u ezines.....