How to use ODBC with a DB connection in ASP.NET

H

HB

Guys,

How to use ODBC with a DB connection in ASP.NET?
each time I try to add the ODBC name in the connection an error telling that
it is not compatible (or so) to use ODBC.

I have .NET 2002 with ver. 1 framework.

Thanks

HB
 
K

Kevin Spencer

Okay, first of all, can you tell me why you want to use ODBC? Are you using
a database product that doesn't have an OLE DB driver? Otherwise, you should
know that ODBC is a nearly-obsolete wrapper for OLE DB, and yields much
poorer performance. If you're using SQL Server or Oracle, there are .Net
managed classes to work with them. Otherwise, if you use OLE DB, you can use
the System.Data.OleDb namespace, and if you really have to use ODBC, you can
use the system.Data.Odbc .Net managed classes.

Next time, the actual error message would be very helpful. :)

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
G

Guest

Since I have the same problem, would add a little bit here
I agree with Kevin to use OleDb for oracle but, in case of databases very old such as db2 or so, what would be the best approach

Thanks
Reza
 
H

HB

Thanks for your help

Error MSG is "The connection you have created does not work with the current
adapter"

How to let the DataGrid to use a connection that is pointed to an ODBC?

Reason of my strange inquiry that the customer I am developing a web app is
not sure if he will use SQL or Oracle
so by using the ODBC I do not have to do any modification due to DB select.
I will appreciate any suggestions.

Thanks

HB
 
K

Kevin Spencer

As I mentioned in my message, some databases don't come with OLE DB drivers.
If the database doesn't have an OLE DB driver, but does have an ODBC driver,
by all means use ODBC, and use the System.Data.Odbc namespace.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

Reza said:
Since I have the same problem, would add a little bit here.
I agree with Kevin to use OleDb for oracle but, in case of databases very
old such as db2 or so, what would be the best approach?
 
W

William LaMartin

Create an aspx page with a DataGrid named DG. Then the following code will
populate it from an Access database with DSN named MyDSN. The datagrid is
also sortable.

Public Class ODBCTest
Inherits System.Web.UI.Page
Protected DC As New Data.Odbc.OdbcConnection
Protected DA As New Data.Odbc.OdbcDataAdapter
Protected WithEvents DG As System.Web.UI.WebControls.DataGrid
Protected DS As New Data.DataSet
Protected DataGrid_Sort As String

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then
DataGrid_Sort = "ID"
Bind_Grid(DataGrid_Sort)
Else
Bind_Grid(DataGrid_Sort)
End If
End Sub

Private Sub Bind_Grid(ByVal sorting As String)
If DC.State = ConnectionState.Open Then DC.Close()
DS.Clear()
DC.ConnectionString = "MaxBufferSize=2048;FIL=MS
Access;DSN=MyDSN;PageTimeout=5"
DC.Open()
DA.SelectCommand = New Data.Odbc.OdbcCommand("select * from [main]",
DC)
DA.Fill(DS)
Dim DV As New Data.DataView(DS.Tables(0))
DV.Sort = sorting
DG.DataSource = DV
DG.Visible = True
DG.AllowSorting = True
DG.DataBind()

End Sub
 
J

jim corey

Pretty sure you're going to need the 1.1 framework
in order to use System.Data.Odbc.

Then you'll have access to stuff like OdbcConnection and OdbcDataAdapter.
 
K

Kevin Spencer

Pretty sure you're going to need the 1.1 framework
in order to use System.Data.Odbc.

That is correct. I just checked.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top