Solved

Using SQL inl Global.asax to set a session value

Posted on 2009-04-11
1
456 Views
Last Modified: 2013-11-26
How do I use the global.asax file to establish a session value that is obtained from a sql database. The connect string is contained in the web.config file.  

The sql query would be similar to this:  select empl_id from employee
Where session.contents ("username") =   employee.user_name.

Session.contents("userid")= employee.empl_id
The global.asax file currently contains the following:
<%@ Application Language="VB" %>
<script runat="server">
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)        
        Dim User As System.Security.Principal.IPrincipal
        User = System.Web.HttpContext.Current.User
        Dim username As String
        username = User.Identity.Name               
        Session.Contents("username") = User.Identity.Name

Open in new window

0
Comment
Question by:reeftec
1 Comment
 
LVL 10

Accepted Solution

by:
Espavo earned 500 total points
ID: 24124685
Here's how you'd do the DB call... (connSQL is the connect string)

Dim conn0 As New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("connSQL").ConnectionString) 
 
Dim cmd0 As New SqlCommand("SELECT empl_id FROM employee 
WHERE user_name = '" & session("username") & "'", conn0)
conn0.Open()
Dim empl_id As Integer = cmd0.ExecuteScalar()
conn0.Close()                   

Open in new window

0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question