Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Professional
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 2nd, 2004, 03:08 PM
Authorized User
 
Join Date: Dec 2003
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


 
Old January 2nd, 2004, 03:21 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
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.
 
Old January 2nd, 2004, 03:32 PM
Authorized User
 
Join Date: Dec 2003
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?

 
Old January 2nd, 2004, 05:23 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
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.
 
Old January 2nd, 2004, 06:00 PM
Authorized User
 
Join Date: Dec 2003
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!






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





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