473,802 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Beginner ?

Hi,

I have a asp.net project I am building in vstudio.net 2003

I have done VB.net projects, but this is my first asp.net(vb.net behind
code)

In a vb.net project I can have a global.bas file, define some public vars,
and then access them within any vb form. I do this with my sqlConnection
object.

I want to do the same with my asp.net app. That is connected once, and use
that connection accross all my asp.net forms

I have in the global.asax.vb file, a publicly declared sqlConnection object.

Within the global.asax.vb I have some functions that use the sqlConnection,
and they work fine.

My problem is that in an asp.net form, the sqlconnection object(declared in
the global) file seems to not be valid.

Is this even possible to do, or does every form have to have its own
declared vars, which would mean I would have to manage my SQL connection on
every form

hope that makes sense

thanks
Nov 18 '05 #1
2 1207
Do not use the same connection throughout your site. This would be very bad
and would limit your scalability severely.
ADO.NET has built in connection pooling.
Therefore you should open a database connection just before you need it on a
page, and close the database connection as soon as possible. The connection
pooling makes this very efficient.

The way most developers handle it is to put the connection string in your
web.config file, like this:
<configuratio n>
<appSettings>
<add key="DSN" value="Server=( local);Database =DBName;UID=sa; PWD="/>
<add key="OtherConne ctionString"
value="Server=( local);Database =DBName2;UID=sa ;PWD="/>
</appSettings>
</configuration>

Then from each page you can get the connection string like this:
Dim sConn As String = ConfigurationSe ttings.AppSetti ngs("DSN")

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
Hire top-notch developers at http://www.able-consulting.com

"AussieRule s" <so*****@nowher e.com> wrote in message
news:ux******** ******@tk2msftn gp13.phx.gbl...
Hi,

I have a asp.net project I am building in vstudio.net 2003

I have done VB.net projects, but this is my first asp.net(vb.net behind
code)

In a vb.net project I can have a global.bas file, define some public vars,
and then access them within any vb form. I do this with my sqlConnection
object.

I want to do the same with my asp.net app. That is connected once, and use
that connection accross all my asp.net forms

I have in the global.asax.vb file, a publicly declared sqlConnection object.
Within the global.asax.vb I have some functions that use the sqlConnection, and they work fine.

My problem is that in an asp.net form, the sqlconnection object(declared in the global) file seems to not be valid.

Is this even possible to do, or does every form have to have its own
declared vars, which would mean I would have to manage my SQL connection on every form

hope that makes sense

thanks

Nov 18 '05 #2
An ASP.Net application is so unlike an executable application that you're
going to have to rethink your entire architecture. The reason for this is
that an executable application exists for the life of the application.
Memory is persistent throughout the life of the application. ASP.Net is a
web application technology. HTTP is stateless, which means that when an
ASP.Net Page is requested, it happens "in a vacuum" so to speak. The web
server has no memory of previous requests, neither of the current Page, nor
of any others. It instantiates the ASP.Net Page class when it receives the
Request. The class exists on the server just long enough to produce the HTTP
Response, which sends the dynamically-generated HTML document to the
browser. Then the class is unloaded.

For this reason, ASP.Net includes some cachinig features that permit the
developer to persist data in memory for longer than a single Page
Request/Response interval. These include the Application, Application Cache,
and Session, to name a few. Data stored in the Application or Application
Cache are truly global; it can be accessed from any Page Class in the
Application Domain, by any client. Session State is confined to any Page
Class instantiated by a given client for the duration of the client Session.

In addition, we're talking about a client-server application with the
potential for a whole slew of clients. For this and some other reasons,
caching ADO.Net objects in any caching mechanism is generally not a good
idea. This is why Connection Pooling was incorporated into the .Net
platform. You can open and close a Connection, but it remains in the
Connection Pool for a period of time, and if another class needs to open a
Connection, it is retrieved from the Pool rather than being re-instantiated,
re-initialized, etc. As long as it uses the same Connection String, it can
be pulled from the Connection Pool quickly and inexpensively.

Therefore, I would recommend that you only store your Connection String
persistently (usually this is in the web.config file), and write your code
to open a fresh Connection with each Page that needs one. Typically, a class
of static Methods can provide all the database-connective functionality you
need. For our company, I created a Class Library of static Database Methods,
which I can use in any application we create, web-based or executable.

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

"AussieRule s" <so*****@nowher e.com> wrote in message
news:ux******** ******@tk2msftn gp13.phx.gbl...
Hi,

I have a asp.net project I am building in vstudio.net 2003

I have done VB.net projects, but this is my first asp.net(vb.net behind
code)

In a vb.net project I can have a global.bas file, define some public vars,
and then access them within any vb form. I do this with my sqlConnection
object.

I want to do the same with my asp.net app. That is connected once, and use
that connection accross all my asp.net forms

I have in the global.asax.vb file, a publicly declared sqlConnection object.
Within the global.asax.vb I have some functions that use the sqlConnection, and they work fine.

My problem is that in an asp.net form, the sqlconnection object(declared in the global) file seems to not be valid.

Is this even possible to do, or does every form have to have its own
declared vars, which would mean I would have to manage my SQL connection on every form

hope that makes sense

thanks

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3082
by: Richard B. Kreckel | last post by:
Hi! I was recently asked what book to recommend for a beginner in C++. I am convinced that you needn't study C in depth before learning C++ (though it helps), but cannot find any beginner's book which isn't aimed at people coming from C/Pascal/Java/Delpi/whatever... However, there seem to be plenty such books for all those other languages. Is there really no literature for people trying to learn programming by starting with C++? ...
8
2383
by: Grrrbau | last post by:
I'm a beginner. I'm looking for a good C++ book. Someone told me about Lafore's "Object-Oriented Programming in C++". What do you think? Grrrbau
7
2945
by: Rensjuh | last post by:
Hello, does someone have / know a good C++ tutorial for beginnners? I would prefer Dutch, but English is also fine. Hoi, heeft / kent iemand nog een goede C++ tutorial voor beginners? Het liefste in Nederlands, maar Engels is ook goed. Thnx, Rensjuh
27
4377
by: MHoffman | last post by:
I am just learning to program, and hoping someone can help me with the following: for a simple calculator, a string is entered into a text box ... how do I prevent the user from entering a text instead of a number, or give an error message? Also, how can I make the program verify there are two valid entries in txtBox1 and txtBox2 to then ENABLE the button operators (ie +, -, /, *).
18
2929
by: mitchellpal | last post by:
Hi guys, am learning c as a beginner language and am finding it rough especially with pointers and data files. What do you think, am i being too pessimistic or thats how it happens for a beginner? Are there better languages than c for a beginner? For instance visual basic or i should just keep the confidence of improving?
20
2299
by: weight gain 2000 | last post by:
Hello all! I'm looking for a very good book for an absolute beginner on VB.net or VB 2005 with emphasis on databases. What would you reccommend? Thanks!
5
2752
by: macca | last post by:
Hi, I'm looking for a good book on PHP design patterns for a OOP beginner - Reccommendations please? Thanks Paul
10
4473
by: Roman Zeilinger | last post by:
Hi I have a beginner question concerning fscanf. First I had a text file which just contained some hex numbers: 0C100012 0C100012 ....
10
2157
by: hamza612 | last post by:
I want to start learning how to program. But I dont know where to start. From what I've heard so far c++ is not a good lang. to learn as a beginner because its very complicated compared to others like python, ruby etc. I would like to know if there is a prerequisite to learning any computer language, is there something I have to learn before learning any computer language, like a basic or core?
22
18154
by: ddg_linux | last post by:
I have been reading about and doing a lot of php code examples from books but now I find myself wanting to do something practical with some of the skills that I have learned. I am a beginner php programmer and looking for a starting point in regards to practical projects to work on. What are some projects that beginner programmers usually start with? Please list a few that would be good for a beginner PHP programmer to
0
9699
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10304
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10285
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10063
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7598
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6838
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5494
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4270
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2966
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.