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>");
Be the first to rate this post
Tags: asp.net, c# access database, oledb connection
10/11/2008 3:25:50 AM