Solved

Using SQL inl Global.asax to set a session value

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

733 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