Click here to Skip to main content
15,919,774 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
This is my VB code for global.asax :-

XML
<%@ Application Language="VB" %>

<script runat="server">

    Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
        ' Code that runs on application startup
        Application("CS") = "server=myServer; user id=myUser; password=MyPaas; database=myData; pooling=true;"
    End Sub

    Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
        ' Code that runs on application shutdown
        Application("CS") = ""

    End Sub

    Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
        ' Code that runs when an unhandled error occurs
    End Sub

    Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
        ' Code that runs when a new session is started
    End Sub

    Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
        ' Code that runs when a session ends.
        ' Note: The Session_End event is raised only when the sessionstate mode
        ' is set to InProc in the Web.config file. If session mode is set to StateServer
        ' or SQLServer, the event is not raised.
    End Sub

</script>



I call this value in VB as :- Dim objConn As New SqlConnection(Application("CS"))

Then how its call in C# ASP.NET
Posted

C#
SqlConnection objConn= new SqlConnection( Application["CS"].ToString());
 
Share this answer
 
Comments
Member 7925220 29-Sep-12 1:40am    
I am getting this error now on my default.aspx

page Error 1 An object reference is required for the non-static field, method, or property 'System.Web.UI.Page.Application.get'
_Amy 29-Sep-12 2:29am    
Since it is an Application object, you can call it dynamically.
Hi,
You can call your application variable like this:
VB
Dim strVal AS String = Application.Item("CS")




--Amit
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900