Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Professional
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 2nd, 2004, 03:08 PM
Authorized User
 
Join Date: Dec 2003
Location: , Wales, United Kingdom.
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default db conn's via global.asax's session_onstart...

Basically I am defining my database connection string from my global.asax (example from a book), but doing it in vb.net 2003 standard is not as easy becuase it's too intelligent. Has anyone else done it this way before?

How do i implement this (below) db connection method with vb.net 2003?? any know? U'd be greatful for any pointers.

This is what I have in my global.asax:

Code:
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
        Dim strDbUrl As String
        strDbUrl = Request.ApplicationPath
        If Right(strDbUrl, 1) <> "/" Then
             strDbUrl &= "/"
        End If
        strDbUrl &= "database/mywebdb.mdb"
        Session("conClass") = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=& Server.MapPath(strDbUrl) &;"
End Sub
(note that the provider is all on one line on my file)

and opening the db from an aspx page would simply be:

conClass = NEW oleDbConnection(session("conclass"))

then u got open or close or wotever u need to do. But doing it this way in VB.NET is not so easy as it refuses to compile correctly.

Thanks,
Dei


  #2 (permalink)  
Old January 2nd, 2004, 03:21 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

What's the compile error? Is the error in your page or the asax.vb?

Peter
------------------------------------------------------
Work smarter, not harder.
  #3 (permalink)  
Old January 2nd, 2004, 03:32 PM
Authorized User
 
Join Date: Dec 2003
Location: , Wales, United Kingdom.
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

the global.asax page is ok, no complaints form vb.net for that page, the error happens when i try to put the connection string in the aspx or ascx file to open the db:

conClass = NEW oleDbConnection(session("conclass"))vb.net says

conClass is not declared.
oleDbconnection is not defined.

but it's declared in the global.asax isn't it? vb.net is too intelligent, or am i missing something?

  #4 (permalink)  
Old January 2nd, 2004, 05:23 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Well, for oleDbConnection, you are probably just missing an Imports statement. You can fully qualify it with System.Data.OleDb.OleDbConnection but seeing as you are probably going to need other data related objects from the OleDb namespace you should import it at the top of your *.aspx.vb class file:

Imports System.Data.OleDb

For conClass:
Unless you have "Dim conClass As oleDbConnection" somewhere in your page, it's not declared. And you don't have it declared in global.asax.vb either. You use it in the session as a collection key, but that doesn't make it declared in the runtime code.

Peter
------------------------------------------------------
Work smarter, not harder.
  #5 (permalink)  
Old January 2nd, 2004, 06:00 PM
Authorized User
 
Join Date: Dec 2003
Location: , Wales, United Kingdom.
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Cool thanks Peter, i put the import thing in and then i put this:
ByVal conClass As OleDbConnection in where u declare the variables. cool huh, no errors on behalf off vb.net now!

thanks a lot!

 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sub Session_OnStart!!? sasha hantz Classic ASP Professional 2 October 27th, 2007 06:29 AM
How to replace db column name with Global variable nesrine C# 0 March 5th, 2007 10:06 AM
How can i replace db column name with Global varia nesrine ASP.NET 2.0 Professional 0 March 5th, 2007 10:05 AM
Global Search&Replace Text in all fields in sql db buddyz SQL Server 2000 10 September 14th, 2006 08:24 AM
Help me about Hit counter using DB and Global.asax yoord BOOK: Beginning ASP.NET 1.0 3 October 16th, 2004 05:02 AM



All times are GMT -4. The time now is 05:07 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.