Link to home
Start Free TrialLog in
Avatar of arthurh88
arthurh88

asked on

Dim a variable accross all my ASP.NET pages?

I have an ASP.NET application with about 20 webforms.

I created Class1.vb, and in this class I have this:

    Public Shared MSSQLCommand As Data.SqlClient.SqlCommand
    Public Shared MSSQLConnection As New Data.SqlClient.SqlConnection

And in all of my webforms, I have this code:
Class1.MSSQLConnection.ConnectionString = ConfigurationManager.ConnectionStrings("DataConnection").ConnectionString

This is causing all kinds of problems, giving errors saying a "connection is string is open" when multiple users access the pages at the same time.

The only other thing I know to do is delcare MSSQLConnection as private on all of my forms.  I'd much rather delcare them once and reference them.  Is there another way I can do this?   I like having code that uses as little repetition as possible...it sems that if I add a
"Private MSSQLConnection as New Data.SqlClient.SqlConnection" at the top of all of my web forms, that I'm being inefficient...or is that the only way to do this?
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of arthurh88
arthurh88

ASKER

makes sense!