troubleshooting Question

How Can i Declare a public Value or Class

Avatar of bduhaish
bduhaishFlag for Saudi Arabia asked on
7 Comments2 Solutions611 ViewsLast Modified:
Hi experts,

I need to use two functions in my hole project in every aspx pages rather that writing them in every page , i triad to create and use public classes put couldn't get it together so here is my request:

Function DecryptConnectionString() As String
Dim b() As Byte =  Convert.FromBase64String(ConfigurationSettings.AppSettings("ConnectionString"))
Dim decryptedConnectionString As String =  System.Text.ASCIIEncoding.ASCII.GetString(b)
Return decryptedConnectionString
End Function

Function DoCon() As SqlConnection
        Dim ConnectionStr As New SqlConnection(DecryptConnectionString())
        Return (ConnectionStr)
End Function

Befor every thing i would like to describe what is going on:
1- i need to encrypt my connection string in the web.config  ----> Done
2- Right now in every page i have to write these two functions
3- My idea is can i just work immediately like define the connection string like below rather than writing theme

             Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
                    If Not Page.IsPostBack Then
                           Dim ConStr As SqlConnection
                           ConStr = DoCon()
                           Dim MySQL As String = "Select Top 10 au_id, au_fname + ' ' + au_lname " & _
                           "as FullName from Authors"
                            Dim ds As DataSet = New DataSet
                            Dim Cmd As New SqlDataAdapter(MySQL, ConStr)
                            Cmd.Fill(ds, "PBAuthors")
                           dgPublishers.DataSource = ds.Tables("PBAuthors").DefaultView
                  End If
             End Sub

 If there is any question I'll be waiting or you can see my old related question about Web.config
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 2 Answers and 7 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros