views:

46

answers:

1

I have this class that contains vars for db connection;

Imports Microsoft.VisualBasic
Imports System.Data.SqlClient
Imports System.Web.Configuration
Public Class DBVars
    Public Shared s As String
    Public Shared con As String = WebConfigurationManager.ConnectionStrings("NMMUDevConnectionStr").ToString()
    Public Shared c As New SqlConnection(con)
    Public Shared x As New SqlCommand(s, c)
    Dim r As SqlDataReader
End Class

I import this to my page like this;

Imports DBVars

I'm then able to access these vars from my page.

But if I try to import them into a user control using the same method the variables are not available. Am I making an error or is this expected?

Thanks.

+1  A: 

Make sure you're accessing them in your usercontrol like so:

Dim useMe As String = DbVars.con

and not something like

Dim x As DbVars = new DbVars()
dim useMe As String = x.con

You need to do this because you've declared them as Shared (static) and not as Instance variables.

Matt Jacobsen