Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_beginners thread: RE: Connecting to Database using OLEDB


Message #1 by "John Kearns" <jdkearns@p...> on Sat, 8 Mar 2003 18:32:14 -0500
Paul,

Here is all the ways ive tried to open the connection.
I receive the error message when I try the .open method.

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Page Language="VB" Debug="true" %>
<html>
 <script language="VB" runat="server">
 Sub btn_click(Sender as object, E as eventargs)

 end sub


    'Dim conAccess as new OLEDBConnection("Provider 
Microsoft.Jet.OLEDB.4.0;Data Source 
C:\Inetpub\wwwroot\aspdotnet\Johns_db.mdb;")


     'dim conAccess as new System.Data.OleDb.OleDbConnection()
     'conAccess.ConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0;Data
Source = C:\Inetpub\wwwroot\aspdotnet\Johns_db.mdb;"

      'Dim conOracle as new OLEDBConnection("Provider=MSDAORA;Data
Source=PROD;User ID=APPS;Password=APPS")

    'dim conDSN as Microsoft.Data.Odbc.OdbcConnection

    'conDSN = New Microsoft.Data.Odbc.OdbcConnection("DSN=John;UID=sa;PWD=")
    'conAccess.open()

    'conOracle.open()

      'WROX 1
    dim myconnection as oledbconnection
    'myconnection = new oledbconnection("Provider 
Microsoft.Jet.OLEDB.4.0;Data Source 
C:\Inetpub\wwwroot\aspdotnet\Johns_db.mdb;")
     myconnection = new oledbconnection("DSN=John;UID=sa;PWD=")
    'myconnection.open
    'Dim mycommand = new oledbcommand(<SQL QUERY>,myconnection)


 </script>
 <head>
  <title>TEST</title>
  <meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
 </head>
 <body>
  <form runat="server">
   Press the button:
   <asp:Button runat="server" text="Press Me" onClick="btn_Click"
runat="server" />
  </form>
 </body>
</html>

----- Original Message -----
From: "Paul Riley" <rilez@t...>
To: "aspx_beginners" <aspx_beginners@p...>
Sent: Thursday, February 20, 2003 11:24 AM
Subject: [aspx_beginners] RE: Connecting to Database using OLEDB


> If you can open the db yourself then you have the odbc driver installed
> almost definitely.
> provider=microsoft.jet.OLEDB.4.0;data
> source=C:\Inetpub\wwwroot\aspdotnet\Johns_db.mdb should work fine. Does
> the asp.net account have access to the database? It is at that path
> isn't it? Aspdotnet isn't a virtual directory or anything? Try entering
> that path into the run command and see what happens to make sure the
> path is correct. Finally have you tried defining a DSN (using the ODBC
> part of control panel (might be under admin tools)) and accessing that
> directly "dsn=moo" iirc assuming u name the dsn moo ... Do you
> understand me?
>
> If none of this works please paste all of your code. I want to double
> check it :)
>
> All the best
> Paul
>
> -----Original Message-----
> From: John Kearns [mailto:jdkearns@p...]
> Sent: 20 February 2003 15:46
> To: aspx_beginners
> Subject: [aspx_beginners] RE: Connecting to Database using OLEDB
>
>
> Thank you very much for your help
>
> But, im still getting the same error, (Expected either a variable,
> constant, Enum, Type, or procedural declaration) when I try this line
>
> myconnection = new oledbconnection("Provider 
> Microsoft.Jet.OLEDB.4.0;Data Source 
> C:\Inetpub\wwwroot\aspdotnet\Johns_db.mdb;")
>
> I dont think its the syntax, It seems like the datatype is not being
> recognized. Could I be missing the correct ODBC driver, is there
> something I need to
> install or include in my aspx page?   This is driving me crazy!!
>
> Thanks,
> John Kearns
>
>
>
>
>
> ----- Original Message -----
> From: "Paul Riley" <rilez@t...>
> To: "aspx_beginners" <aspx_beginners@p...>
> Sent: Thursday, February 20, 2003 4:21 AM
> Subject: [aspx_beginners] RE: Connecting to Database using OLEDB
>
>
> > OK. Need to rush out really but heres some code that I know works
> >
> > dim myconnection as oledbconnection
> > myconnection = new oledbconnection(<INSERT ALL YOUR STUFF IN HERE)
> > myconnection.open Dim mycommand = new oledbcommand(<SQL
> > QUERY>,myconnection)
> >
> >
> >
> > -----Original Message-----
> > From: John Kearns [mailto:jdkearns@p...]
> > Sent: 20 February 2003 06:28
> > To: aspx_beginners
> > Subject: [aspx_beginners] Connecting to Database using OLEDB
> >
> >
> > I can really use some help here.
> >
> > I am trying to make a simple connection to an access database. I
> > create my connection object...
> >    dim conAccess as new System.Data.OleDb.OleDbConnection()
> >
> > When I set the creation string..
> >    conAccess.ConnectionString = "Provider 
> > Microsoft.Jet.OLEDB.4.0;Data
> >
> > Source = C:\Inetpub\wwwroot\aspdotnet\Johns_db.mdb;"
> >
> > I get the following error
> >     Compiler Error Message: BC30188: Expected either a variable,
> > constant, Enum, Type, or procedural declaration.
> >
> > Am I missing something?
> > ---
> > Change your mail options at http://p2p.wrox.com/manager.asp or to
> > unsubscribe send a blank email to 
> >
> >
> > ---
> > Change your mail options at http://p2p.wrox.com/manager.asp or to
> > unsubscribe send a blank email to
> >
>
>
>
>
>

Message #2 by "Paul Riley" <rilez@t...> on Sun, 9 Mar 2003 01:13:45 -0000
OK. I've seen what your problem is but thanks again to aspnet for its
crappy bug reporting. The code needs to be inside a page_load sub eg...

<%@Page Language="VB" debug="true"%>
<%@ Import Namespace = "System.Data" %>
<%@ Import Namespace = "System.Data.oledb" %>
<%@ Import Namespace = "System.Data.odbc" %>
<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">
<html>
<head>
<title>Quick view</title>
<link rel="stylesheet" href="/include/style.css"/>
</head>
<body>
<div id="output" runat="server"/>
<asp:datagrid id="QuickView" runat="server"/>
<script runat="server">
sub page_load()
	Dim strconn As string
	strconn = request.querystring("connection")
	Dim mydatatable = new datatable
	try
	If strconn.startswith("odbc") then
		Dim myconnection As odbcconnection
		myconnection = New
odbcconnection(ConfigurationSettings.AppSettings.item(strconn))
		Dim myadapter = new odbcdataadapter("SELECT * FROM " &
request.querystring("table"),myconnection)
		myadapter.fill(mydatatable)
		myconnection.close
		myadapter = nothing
		myconnection = nothing
	else
		Dim myconnection As oledbconnection
		myconnection = New
oledbconnection(ConfigurationSettings.AppSettings.item(strconn))
		Dim myadapter = new oledbdataadapter("SELECT * FROM " &
request.querystring("table"),myconnection)
		myadapter.fill(mydatatable)
		myadapter.close
		myconnection.close
		myadapter = nothing
		myconnection = nothing
	End if
	QuickView.datasource = mydatatable
	QuickView.databind
	Catch objError As Exception
		output.innerhtml = "<b>* Error</b>: " & objError.Message
	End Try
End sub
</script>
</body>
</html>

That code is a general report viewer (anyone's welcome to use if they
want but I can do a hell of a lot better ;)). It should give you an idea
of what to do. The first thing to do when you get an error is to search
on google on it. In this case the first response was
http://www.google.co.uk/search?q=cache:t1QrdwecV84C:www.dotnet247.com/24
7reference/msgs/2/10957.aspx+BC30188:+Expected+either+a+variable,+&hl=en
&ie=UTF-8

Anyway, hth.

Paul

-----Original Message-----
From: John Kearns [mailto:jdkearns@p...] 
Sent: 08 March 2003 23:32
To: aspx_beginners
Subject: [aspx_beginners] RE: Connecting to Database using OLEDB


Paul,

Here is all the ways ive tried to open the connection.
I receive the error message when I try the .open method.

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Page Language="VB" Debug="true" %>
<html>
 <script language="VB" runat="server">
 Sub btn_click(Sender as object, E as eventargs)

 end sub


    'Dim conAccess as new OLEDBConnection("Provider 
Microsoft.Jet.OLEDB.4.0;Data Source 
C:\Inetpub\wwwroot\aspdotnet\Johns_db.mdb;")


     'dim conAccess as new System.Data.OleDb.OleDbConnection()
     'conAccess.ConnectionString = "Provider 
Microsoft.Jet.OLEDB.4.0;Data Source 
C:\Inetpub\wwwroot\aspdotnet\Johns_db.mdb;"

      'Dim conOracle as new OLEDBConnection("Provider=MSDAORA;Data
Source=PROD;User ID=APPS;Password=APPS")

    'dim conDSN as Microsoft.Data.Odbc.OdbcConnection

    'conDSN = New
Microsoft.Data.Odbc.OdbcConnection("DSN=John;UID=sa;PWD=")
    'conAccess.open()

    'conOracle.open()

      'WROX 1
    dim myconnection as oledbconnection
    'myconnection = new oledbconnection("Provider 
Microsoft.Jet.OLEDB.4.0;Data Source 
C:\Inetpub\wwwroot\aspdotnet\Johns_db.mdb;")
     myconnection = new oledbconnection("DSN=John;UID=sa;PWD=")
    'myconnection.open
    'Dim mycommand = new oledbcommand(<SQL QUERY>,myconnection)


 </script>
 <head>
  <title>TEST</title>
  <meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
</head>  <body>
  <form runat="server">
   Press the button:
   <asp:Button runat="server" text="Press Me" onClick="btn_Click"
runat="server" />
  </form>
 </body>
</html>

----- Original Message -----
From: "Paul Riley" <rilez@t...>
To: "aspx_beginners" <aspx_beginners@p...>
Sent: Thursday, February 20, 2003 11:24 AM
Subject: [aspx_beginners] RE: Connecting to Database using OLEDB


> If you can open the db yourself then you have the odbc driver 
> installed almost definitely. provider=microsoft.jet.OLEDB.4.0;data
> source=C:\Inetpub\wwwroot\aspdotnet\Johns_db.mdb should work fine.
Does
> the asp.net account have access to the database? It is at that path
> isn't it? Aspdotnet isn't a virtual directory or anything? Try
entering
> that path into the run command and see what happens to make sure the
> path is correct. Finally have you tried defining a DSN (using the ODBC
> part of control panel (might be under admin tools)) and accessing that
> directly "dsn=moo" iirc assuming u name the dsn moo ... Do you
> understand me?
>
> If none of this works please paste all of your code. I want to double 
> check it :)
>
> All the best
> Paul
>
> -----Original Message-----
> From: John Kearns [mailto:jdkearns@p...]
> Sent: 20 February 2003 15:46
> To: aspx_beginners
> Subject: [aspx_beginners] RE: Connecting to Database using OLEDB
>
>
> Thank you very much for your help
>
> But, im still getting the same error, (Expected either a variable, 
> constant, Enum, Type, or procedural declaration) when I try this line
>
> myconnection = new oledbconnection("Provider = 
> Microsoft.Jet.OLEDB.4.0;Data Source 
> C:\Inetpub\wwwroot\aspdotnet\Johns_db.mdb;")
>
> I dont think its the syntax, It seems like the datatype is not being 
> recognized. Could I be missing the correct ODBC driver, is there 
> something I need to
> install or include in my aspx page?   This is driving me crazy!!
>
> Thanks,
> John Kearns
>
>
>
>
>
> ----- Original Message -----
> From: "Paul Riley" <rilez@t...>
> To: "aspx_beginners" <aspx_beginners@p...>
> Sent: Thursday, February 20, 2003 4:21 AM
> Subject: [aspx_beginners] RE: Connecting to Database using OLEDB
>
>
> > OK. Need to rush out really but heres some code that I know works
> >
> > dim myconnection as oledbconnection
> > myconnection = new oledbconnection(<INSERT ALL YOUR STUFF IN HERE) 
> > myconnection.open Dim mycommand = new oledbcommand(<SQL
> > QUERY>,myconnection)
> >
> >
> >
> > -----Original Message-----
> > From: John Kearns [mailto:jdkearns@p...]
> > Sent: 20 February 2003 06:28
> > To: aspx_beginners
> > Subject: [aspx_beginners] Connecting to Database using OLEDB
> >
> >
> > I can really use some help here.
> >
> > I am trying to make a simple connection to an access database. I 
> > create my connection object...
> >    dim conAccess as new System.Data.OleDb.OleDbConnection()
> >
> > When I set the creation string..
> >    conAccess.ConnectionString = "Provider = 
> > Microsoft.Jet.OLEDB.4.0;Data
> >
> > Source = C:\Inetpub\wwwroot\aspdotnet\Johns_db.mdb;"
> >
> > I get the following error
> >     Compiler Error Message: BC30188: Expected either a variable, 
> > constant, Enum, Type, or procedural declaration.
> >
> > Am I missing something?
> > ---
> > Change your mail options at http://p2p.wrox.com/manager.asp or to 
> > unsubscribe send a blank email to 
> >
> >
> > ---
> > Change your mail options at http://p2p.wrox.com/manager.asp or to 
> > unsubscribe send a blank email to
> >
>
>
> ---
> Change your mail options at http://p2p.wrox.com/manager.asp or to 
> unsubscribe send a blank email to 
>
>
> ---
> Change your mail options at http://p2p.wrox.com/manager.asp or to 
> unsubscribe send a blank email to
>




  Return to Index