?
Solved

Using SQL inl Global.asax to set a session value

Posted on 2009-04-11
1
Medium Priority
?
460 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 10

Accepted Solution

by:
Espavo earned 2000 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

How To Install Bash on Windows 10

Windows’ budding partnership with Canonical has certainly led to some great improvements. One of them being the ability to use Bash on your Windows machine without third party applications! This might be one of the greatest things a cloud engineer in a Windows environment can do!

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…
Suggested Courses
Course of the Month8 days, 21 hours left to enroll

764 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