Solved

Using SQL inl Global.asax to set a session value

Posted on 2009-04-11
1
454 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

867 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now