Net-informations.com
SiteMap  | About    

ASP.NET ODBC Connection

An instance of the OdbcConnection Class in ASP.NET is supported the ODBC Data Provider. The OdbcConnection instance takes Connection String as argument and pass the value to the Constructor statement. When the connection is established between ASP.NET application and the Data Source the SQL Commands will execute with the help of the Command Object and retrieve or manipulate data in the database.

vb.net
  Dim connectionString As String
  Dim connection As OdbcConnection
  connectionString = ConfigurationManager.ConnectionStrings("ODBCConnection").ToString

connection = New OdbcConnection(connectionString)

C#
  string connectionString = ConfigurationManager.ConnectionStrings["ODBCConnection"].ToString();

OdbcConnection connection = new OdbcConnection(connectionString);

Once the Database activity is over you should be closed the Connection and release the Data Source resources . The Close() method in OdbcConnection Class is used to close the Database Connection. The Close method rolls back any pending transactions and releases the Connection from the Database connected by the ODBC Data Provider .

The following ASP.NET program trying to establish connection to an ODBC Data source and display the message in Label control.

Copy and paste the following content into your web.config file and provide the parameter values.

web.config

  

<?xml version="1.0"?>
<configuration>
  <connectionStrings>
	<add name="ODBCConnection"
		 connectionString="Driver={Microsoft Access Driver (*.mdb)}; DBQ=your database path\yourdatabasename.mdb;"
		 providerName="System.Data.SqlClient" />
  </connectionStrings>
</configuration>

Default.aspx

  

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
	<title>Untitled Page</title>
</head>
<body>
	<form id="form1" runat="server">
	<div>
		<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
	</div>
	<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
	</form>
</body>
</html>


Click the following links to see full source code

C# Source Code
VB.NET Source Code
default.aspx.cs
default.aspx.vb






net-informations.com (C) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.