Solved

Using SQL inl Global.asax to set a session value

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 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

20 Experts available now in Live!

Get 1:1 Help Now