Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_beginners thread: ODBC data connection problem


Message #1 by "James S. Wile" <jsw@l...> on Thu, 21 Nov 2002 17:37:22
I recently downloaded and installed the ODBC.NET Data Provider from 
Microsoft.  My program begins as follows:
 
<%@ Page Language="VB" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.Odbc" %>
<script runat="server">
 
    Sub Page_Load()
      Dim strConnection as String 
      Dim strSql as String     

      strConnection = "DSN=U2200-AP3-32;SRVR=AIS3;UID=ACP593;PWD="
     
      strSql = " SELECT FIRST_NAME, MIDDLE_INITL, LAST_NAME " & _
               " FROM   CUST "                                & _
               " WHERE  LAST_NAME = 'WILE'"
      
      Dim objConnection as New OdbcConnection(strConnection)
           .
           .
I Don't know if that connection string will work yet, but I don't even 
get that far.  I generate the following error when trying to run this 
page:
 
Compiler Error Message: BC30002: Type 'OdbcConnection' is not defined.

Source Error:

Line 16:       
Line 17:       Dim objConnection as New OdbcConnection(strConnection)
Line 18:         . 
Line 19:         .
  
As part of the setup for the ODBC.NET Data Provider, the 
Microsoft.Data.Odbc namespace was supposedly added to the Global Assembly 
Cache, although I don't know where that is to see if it's there.  I also 
tried replacing the line: <%@ import Namespace="System.Data.Odbc" %> with 
<%@ import Namespace="Microsoft.Data.Odbc" %>, but I generated the same 
error.

What do I need to do to remedy this? 
Message #2 by "James S. Wile" <jsw@l...> on Fri, 22 Nov 2002 18:04:52
> I recently downloaded and installed the ODBC.NET Data Provider from 
M> icrosoft.  My program begins as follows:
 > 
<> %@ Page Language="VB" %>
<> %@ import Namespace="System.Data" %>
<> %@ import Namespace="System.Data.Odbc" %>
<> script runat="server">
 > 
 >    Sub Page_Load()
 >      Dim strConnection as String 
 >      Dim strSql as String     

>       strConnection = "DSN=U2200-AP3-32;SRVR=AIS3;UID=ACP593;PWD="
 >     
 >      strSql = " SELECT FIRST_NAME, MIDDLE_INITL, LAST_NAME " & _
 >               " FROM   CUST "                                & _
 >               " WHERE  LAST_NAME = 'WILE'"
 >      
 >      Dim objConnection as New OdbcConnection(strConnection)
 >           .
 >           .
I>  Don't know if that connection string will work yet, but I don't even 
g> et that far.  I generate the following error when trying to run this 
p> age:
 > 
C> ompiler Error Message: BC30002: Type 'OdbcConnection' is not defined.

> Source Error:

> Line 16:       
L> ine 17:       Dim objConnection as New OdbcConnection(strConnection)
L> ine 18:         . 
L> ine 19:         .
 >  
A> s part of the setup for the ODBC.NET Data Provider, the 
M> icrosoft.Data.Odbc namespace was supposedly added to the Global 
Assembly 
C> ache, although I don't know where that is to see if it's there.  I 
also 
t> ried replacing the line: <%@ import Namespace="System.Data.Odbc" %> 
with 
<> %@ import Namespace="Microsoft.Data.Odbc" %>, but I generated the same 
e> rror.

> What do I need to do to remedy this? 

I found out the answer to this myself.  All I needed to do was to change 
my first 3 lines of code as follows:

<%@ Page Language="VB" Debug="True" CompilerOptions='/R:"C:\Program 
Files\Microsoft.NET\Odbc.Net\Microsoft.data.odbc.dll"'%>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace = "Microsoft.Data.Odbc" %>

The CompilerOptions clause is what did it, as well as using the 
Microsoft.Data.Odbc namespace instead of the System.Data.Odbc namespace.  
I discovered a problem with this, though, when using WebMatrix as my 
editor.  The next time I reload the program after having saved it as 
shown, the Page directive is changed to simply: <%@ Page %> and I lose 
the rest of it.  Does anyone have any suggestions about this?

Message #3 by "Mark Harwood" <mark@h...> on Mon, 25 Nov 2002 08:32:53 -0000
Why are you trying to use odbc

Try using oledb

Dim objConnection As New
system.Data.OleDb.OleDbConnection(strConnection)

Also I would never keep any server username or password details
connection details I'm using in code in a request to a list like this.
You never know who's looking.


Mark Harwood

-----Original Message-----
From: James S. Wile [mailto:jsw@l...] 
Sent: 22 November 2002 18:05
To: aspx_beginners
Subject: [aspx_beginners] Re: ODBC data connection problem

> I recently downloaded and installed the ODBC.NET Data Provider from 
M> icrosoft.  My program begins as follows:
 > 
<> %@ Page Language="VB" %>
<> %@ import Namespace="System.Data" %>
<> %@ import Namespace="System.Data.Odbc" %>
<> script runat="server">
 > 
 >    Sub Page_Load()
 >      Dim strConnection as String 
 >      Dim strSql as String     

>       strConnection = "DSN=U2200-AP3-32;SRVR=AIS3;UID=ACP593;PWD="
 >     
 >      strSql = " SELECT FIRST_NAME, MIDDLE_INITL, LAST_NAME " & _
 >               " FROM   CUST "                                & _
 >               " WHERE  LAST_NAME = 'WILE'"
 >      
 >      Dim objConnection as New OdbcConnection(strConnection)
 >           .
 >           .
I>  Don't know if that connection string will work yet, but I don't even

g> et that far.  I generate the following error when trying to run this 
p> age:
 > 
C> ompiler Error Message: BC30002: Type 'OdbcConnection' is not defined.

> Source Error:

> Line 16:       
L> ine 17:       Dim objConnection as New OdbcConnection(strConnection)
L> ine 18:         . 
L> ine 19:         .
 >  
A> s part of the setup for the ODBC.NET Data Provider, the 
M> icrosoft.Data.Odbc namespace was supposedly added to the Global 
Assembly 
C> ache, although I don't know where that is to see if it's there.  I 
also 
t> ried replacing the line: <%@ import Namespace="System.Data.Odbc" %> 
with 
<> %@ import Namespace="Microsoft.Data.Odbc" %>, but I generated the
same 
e> rror.

> What do I need to do to remedy this? 

I found out the answer to this myself.  All I needed to do was to change

my first 3 lines of code as follows:

<%@ Page Language="VB" Debug="True" CompilerOptions='/R:"C:\Program 
Files\Microsoft.NET\Odbc.Net\Microsoft.data.odbc.dll"'%>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace = "Microsoft.Data.Odbc" %>

The CompilerOptions clause is what did it, as well as using the 
Microsoft.Data.Odbc namespace instead of the System.Data.Odbc namespace.

I discovered a problem with this, though, when using WebMatrix as my 
editor.  The next time I reload the program after having saved it as 
shown, the Page directive is changed to simply: <%@ Page %> and I lose 
the rest of it.  Does anyone have any suggestions about this?



  Return to Index