473,385 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 1191
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:
<configuration>
<appSettings>
<add key="DSN" value="Server=(local);Database=DBName;UID=sa;PWD="/>
<add key="OtherConnectionString"
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 = ConfigurationSettings.AppSettings("DSN")

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

"AussieRules" <so*****@nowhere.com> wrote in message
news:ux**************@tk2msftngp13.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.

"AussieRules" <so*****@nowhere.com> wrote in message
news:ux**************@tk2msftngp13.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
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...
8
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
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...
27
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...
18
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?...
20
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
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
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
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...
22
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.