Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. Global.aspx

Global.aspx

Scheduled Pinned Locked Moved Visual Basic
databasesql-serversysadminsecurityhelp
2 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Pete Newman
    wrote on last edited by
    #1

    hi, ive been trying to edit the global.aspx file to create an application connection to the SQL Server. Code <%@ Application Language="VB" %> <%@ Import Namespace="System.Data.SQLCLIENT" %> <%@ Import Namespace="System.Data" %> Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs) ' Code that runs on application startup Dim sqlConn As New SqlClient.SqlConnection Dim sqlCommand As New SqlClient.SqlCommand Dim ConectStr As String = "Data Source=DEVELOPMENT\SQLEXPRESS;Initial Catalog=Testdata;Integrated Security=True" sqlConn = New SqlClient.SqlConnection("ConectStr") sqlConn.Open() Application("SQLConnection") = sqlConn End Sub Any ideas where im going wrong as this keeps failing. Thanks in advance I really do need help..... all this computer stuff is way over my head !!</x-turndown>

    D 1 Reply Last reply
    0
    • P Pete Newman

      hi, ive been trying to edit the global.aspx file to create an application connection to the SQL Server. Code <%@ Application Language="VB" %> <%@ Import Namespace="System.Data.SQLCLIENT" %> <%@ Import Namespace="System.Data" %> Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs) ' Code that runs on application startup Dim sqlConn As New SqlClient.SqlConnection Dim sqlCommand As New SqlClient.SqlCommand Dim ConectStr As String = "Data Source=DEVELOPMENT\SQLEXPRESS;Initial Catalog=Testdata;Integrated Security=True" sqlConn = New SqlClient.SqlConnection("ConectStr") sqlConn.Open() Application("SQLConnection") = sqlConn End Sub Any ideas where im going wrong as this keeps failing. Thanks in advance I really do need help..... all this computer stuff is way over my head !!</x-turndown>

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      You've got multiple problems with this. First, ApplicationStart only executes the first time a page request is made to your site. It will never execute again. Second, since this only executes once, anything this code does will never get executed for any subsequent page requests. Since web applications are stateless, your page code has to be written so that each page requests builds and destroys the objects it needs on EVERY request, not just the first one. Any object you create in ApplicationStart will fall out of scope and not be usable anywhere in your page's code. So, building an SQL connection in ApplicationStart will not do you any good since they will no longer exist after ApplicationStart is done executing. Lastly, you REALLY have to be specific in your posts as to what the code is supposed to be doing and supply any and all error messages you get along with the lines of code that the errors occur on. Without that, all you've done is pulled your car into the dealership and told the service guy "It's broke." How's he supposed to know what you're talking about?

      Dave Kreskowiak Microsoft MVP - Visual Basic

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups