ASP.Net Access Database Connection

Updated on 03 Apr 2012,
Published on 12 Feb 2008

Simple way for ASP.Net 2.0 access database connection is DSN. You can use OBDC drivers for Ms Access Database connection. ODBC provides Microsoft Access Drivers (*.mdb).

Just create DSN on web server through Data Sources (ODBC). Select the Ms Access Database file path by browsing it. In ASP.Net 2.0 save your connection string AppSettings section of web.config file:

<appSettings>
        <add key="myDSN" value="DSN=myDSN" />
</appSettings>

DSN (Data Source Name)

Enter the data source name created in ODBC connectivity.

Import Namespaces for ODBC

Imports System.Data
Imports System.Data.Odbc

Source code below shows the use of ODBC to connect to MS Access Database using VB code:

' Access Database ODBC connection string
Dim connStr As String = ConfigurationManager.AppSettings("myDSN").ToString()

' Object created for Odbc Connection
Dim myAccessConnection As New OdbcConnection(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 Then
    myAccessConnection.Open()
End If

' Message that displays the access database connection state
' 1 for open
' 0 for closed
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 Then
    myAccessConnection.Close()
End If

Continue to next tutorial: ASP.Net C# access database to learn how to connect to MS Access database using C# code.

0 Responses to "ASP.Net Access Database Connection"
Leave a Comment
* required
* required
* will not be published
* optional
* hint: http://www.example.com
  • Subscribe via Email
  • HIRE EzineASP.Net Developers