Trying to access SQL data with session value (I'm a total newb to VB and .Net 2.0)

I'm not an expert programmer in any way shape or form but I'm working on my next project and need some assistance. We have an existing site that is up and been running for a couple years and needs an uplift to asp .net 2.0. All our data is in a SQL 2005 db and is accessed by 3 groups, administrators, techs and clients. Admin see all data and all functions, Techs only see their calls and clients only see their data but some clients have 20 users. Our SQL db uses a field named accounID to tied multiple accounts together. On our old site once a user logged on a session was created (stored in a 2nd db) that tied the users name to their accountID. Then we can use the session accountID to pull from the db and the customer only see's what we want them to see.In ASP .Net 2.0 I have looked at using cookies, profiles and sessions to perform the same function. For now I want to stick with sessions. Creating logins, create new users, ect is easing enough with the built in controls in .net but for the life of me I can figure out how to tie the logged in user with a session to associate the accountID with that user. Once I get past this one step the rest will be a breeze. I created a dummy page using a fixed session that works but of course this needs to be dynamic not fixed. The old site only uses one page for all three account types with many clients and I would like to keep it that way. Here's the code on the code behind page using page load to create the static session. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load, LoginName1.DataBinding
Dim firstName As String =
"DSS"
Session("UserName") = firstName
mylabel.Text = Session("UserName")
End Sub
As the page is loaded DSS becomes the session "username" and the data grid on the page uses the variable "dss" in the qry and pulls DSS data. I realize you all probably need more info and I appreciate the time.Thanks
0
mylu
3/11/2008 4:01:36 PM
asp.net.state-management 8807 articles. 0 followers. Follow

5 Replies
618 Views

Similar Articles

[PageSpeed] 34

I possible problem that I noticed is that you do not have the code enclosed in:

If Not Page.IsPostBack Then
   'Code goes here
End If

Have that code run on every postback could be causing some problems.


Mark this post as the "Answer" if it was the answer.
0
sswanner1
3/11/2008 4:28:33 PM

hi,

try to like this,

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

if Not Page.IsPostBack then
  Session("UserName") = firstName
  mylabel.Text = Session("UserName")

end if

End Sub

 


The Page_Load subroutine runs EVERY time the page is loaded. If you want to execute the code in the Page_Load subroutine only the FIRST time the page is loaded, you can use the Page.IsPostBack property. If the Page.IsPostBack property is false, the page is loaded for the first time, if it is true, the page is posted back to the server.

 

 

0
gopalanmani
3/11/2008 7:03:32 PM
Thanks for the response as I said I'm a newb the .net here. 

I do know that using the code you gave will generate and exception because firstname is not declared. What I need to do is somehow create a session from data stored in the ASP_user table from the accountID associated with the user. accoutID is a field I added to the asp_user table. Bob logs in using the ASP.net login control (which works fine) is then redirected to the client page at the same time a session is created that looks at Bobs data in the db and reads his accountID (in asp_user table) that in turn is used in a gridview to pulls bobs data.

The whole point is to not pass parameters via a URL which is not secure.Make since? 

 

 

0
mylu
3/11/2008 8:05:36 PM

After looking at your post again, I noticed that you are handling login.databound in your page_load.  Why don't you set the session in the actual login event?  Another question:  Why not just you my.user.name as opposed to storing it in session?


Mark this post as the "Answer" if it was the answer.
0
sswanner1
3/11/2008 8:14:44 PM

Well because I'm learning and don't know the proper way. login.databound worked and it was a start. I was just happy to see the page post data. I'm assuming my.user.name is the command to read the user name from the login control? That's what I was looking for in the first place. Now all I got's to do if figure out how to use it. Is there a goob book that list all the .Net commands and their function like session, my.user.name ect? 

**edit**

Well I got the first have of the issue resolve, Bob logs in and pulls Bob's data, John logs in and pulls Johns data:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
mylabel.Text = My.User.Name
End Sub

But Tell me If my logic is correct.

Bob logs in with UID Bob so does Lucy and Mike and they all have the accountID = DSS
So the logic would be
IF bob = my.user.name
THEN GET bobs accountID from asp_user tbl "accountID"
with SQLREAD pass "accountID" to mylabel.text
The run the qry.

Thanks

 

0
mylu
3/11/2008 8:36:58 PM
Reply:

Similar Artilces:

.NET 2.0 Data Connection (.NET 2.0 Beta Data Provider)
I have installed the .NET 2.0 Beta Data Provider, in the server explorer in Visual Studio 2005 I have tried to connect to this provider but I can not see it in the list. Is there something else you need to do to see this other than what is in the instructions or is this not supported yet? Hi Dean, I assume you mean ASE ADO.NET 2.0 Beta. I'm attaching the html readme for this product that you should have from downloading it. Are you talking about using Server Explorer to see the Provider? This functionality isn't working yet and should be available on GA or shortly ...

.Net 2.0 Web application using Vb.net is unable to create object of another dll writen in C# .net 2.0
Hi, I habe created one ASP.net web application using Vb.net which is adding reference of dlls written in C# and .net 2.0. But whenever trying to create object of referencing dll, it is throwing error :Object reference does not set to an object. But, locally it is working fine,. In the server i have deployed the .aspx files and dll files in the bin. There were already an web.config in the server which is of .net 1.1. But checked it is retrieving value for that web.config correctly. Should i have to deply any other files and if not what can be the solution for this? Please help. Thanks, So...

Differences between .net 1, .net 1.1, .net 2.0 and .net 3.0 #2
Hi, This seems to be a common question, but i havent got an answer yet:(Can, any one please explain me the differences between these versions.If you keep your feet firmly on the ground, you'll have trouble putting on your pants! There are too many differences for one email - - from 1.0 to 1.1 (not a whole lot of real change, other than fixes, at least compared to 1.1 to 2.0) With 2.0, there were many new declarative controls, with many new ideas added in With 3.0, it's a superset of 2.0 - instead of replacing the installation completely, it just 'added on' new functionality - I would...

Access .Net 2.0 Application from .Net 2.0 Web Site
I need to populate a specific form in a .Net desktop application from a .net web application.  Is there an easy way to go about this? Hi, Based on my understanding, you want to start an executable application from your ASP.NET websit, right? We can invoke Process.Start method (http://msdn.microsoft.com/en-us/library/system.diagnostics.process.start.aspx) to launch an executable application from ASP.NET application. Note: Please keep in mind, the ASP.NET application is running on the server, so it will start the executable application that exists in the server.   I look...

SQL query that works in SQL Server Management Studio, but doesn't on .NET 2.0 page
SELECT favorites.FID, favorites.filename, favorites.username, files.status, files.private, files.views, files.title FROM favorites INNER JOIN files ON favorites.filename = files.filename WHERE (favorites.username = @username) AND (files.status IS NULL) AND (files.private = @private)@private is manually set to 'no'@username is set to profile.usernamewhen I run the above query in microsoft sql server mgmt studio express on the database, it presents all the information i'm asking for very easily. however when i try to implement this query on a aspx .net2.0 page with teh sqldatasourc...

Session Management in SQL SERVER for .NET 2.0
Hi, I need to maintain Session variables in the Sql Server Database. But for maintaining the Session, the aspnet_regsql.exe must be run in the .net 2.0 framework. I have a clarification on running aspnet_regsql.exe in asp.net 2.0 I have a Web Server 'TESTWEB' where my source code resides. The Database server resides in another server. The exe must be run in the command prompt from C:\Windows\Microsoft.Net\Framework\v2.0\mentioning the parameters as Database server name, User id, Password. But the doubt is, whether this exe must be run only from this web server 'TESTWEB'...

Differences between .net 1, .net 1.1, .net 2.0 and .net 3.0
Hi, This seems to be a common question, but i havent got an answer yet:(Can, any one please explain me the differences between these versions.If you keep your feet firmly on the ground, you'll have trouble putting on your pants! Have a look into this links http://en.wikipedia.org/wiki/.NET_Framework http://blogs.msdn.com/mohammadakif/archive/2006/12/03/net-3-0-different-versions-of-the-net-framework.aspx http://www.codeproject.com/aspnet/ComparisonASP1xASP20.aspAshok Rajawww.iGold.inDon't forget to click "Mark as Answer" on the post that helped you. This credits that m...

Getting only the first paragraph of data from sql server 2005 in vb.net 2.0
Hi all, I have a table in sql server which consists of two colums. column 1 contain "id" integer and column 2 contain "body" varchar(max). For example: id - 1 body - French Industrial production sharply decreased 1.5% month-on-month in November, reversing from a 2.1% increase seen in October, the statistical office Insee said in a report Thursday. Economists were looking for a 0.6% fall. Production in the automotive industry fell steeply 5.3% versus 7.5% rise in October, while energy output declined 2% from 2.1% recorded in the previous month. In the construction...

Access to the ADO.net Managed Provider 'SqlClientFactory' was denied in the data source with ID 'SqlDataSource1' because of security settings.
I am getting "Access to the ADO.net Managed Provider 'SqlClientFactory' was denied in the data source with ID 'SqlDataSource1' because of security settings. " When I use database connection to my web applicaiton. Can you tell me what is the problem. I have posted in forum http://forums.asp.net/thread/1306653.aspx but they asked me to post here. I am recieving the same error.  Did you find a solution to this? I was recieving this error while developing webparts for WSS SP2 running on .NET 2.0. I created a custom trust file with a permissionset and codegroup for my assembly...

what is new in vb net for Net 2.0 ?
where can I find an article with all what is new in vb net for Net 2.0 ? thank youangiras ???? http://whidbey.msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vbcn/html/d7e97396-7f42-4873-a81c-4ebcc4b6ca02.aspThanks,Teemu KeiskiFinland, EU...

What's compatible with DW.NET 2.0 and DW.NET 2.5
The group I work with does nothing but PB applications. Finally there is some interest in moving some of our applications away from PB towards the .Net area. Currently we are not interested in what PB 11 is offering in the .NET area. We would like to be in a more 'native' .NET environment. Now with that being said , we are in the VERY early stages of using Visual Studio and Datawindow.NET. We have already found some issues with DW.NET 2.5 and VS 2008 that are making it difficult to move forward. So here is my question. What versions of VS and DW.NET actually work well tog...

What's compatible with DW.NET 2.0 and DW.NET 2.5?
The group I work with does nothing but PB applications. Finally there is some interest in moving some of our applications away from PB towards the .Net area. Currently we are not interested in what PB 11 is offering in the .NET area. We would like to be in a more 'native' .NET environment. Now with that being said , we are in the VERY early stages of using Visual Studio and Datawindow.NET. We have already found some issues with DW.NET 2.5 and VS 2008 that are making it difficult to move forward. So here is my question. What versions of VS and DW.NET actually work well tog...

Request for the permission of type 'System.Net.WebPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. #2
How do you solve this problem in pb105 ? Request for the permission of type 'System.Net.WebPermission,System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. ...

The .Net Data SQL Provider (System.Data.SqlClient) requires Microsoft Data Access Components(MDAC) version 2.6 or later.
I am getting error like The .Net Data SQL Provider (System.Data.SqlClient) requires Microsoft Data Access Components(MDAC) version 2.6 or later. i am working with windowsXP. Already in my system i have MDAC 2.7. I donot know why am i getting error like this. anybody help me please...

Web resources about - Trying to access SQL data with session value (I'm a total newb to VB and .Net 2.0) - asp.net.state-management

Joint session of the United States Congress - Wikipedia, the free encyclopedia
Joint sessions of the United States Congress are the gatherings together of both houses of the United States Congress (the House of Representatives ...

Wall St ends shortened session steady
US markets lack direction in abbreviated post-Thanksgiving trading session.

Perth pub, nightclub opening hours to extend - Sunday Sessions, WA
AS THE east coast of Australia cracks down on late-night drinking, Western Australia is heading in the opposite direction.

Tomas Cubelli arrives in Canberra as Brumbies land blows at AIS boxing session
An immigration hold-up and passport confusion threatened to delay Tomas Cubelli's ACT Brumbies' arrival.

S&P 500 ends flat in holiday-shortened session
The S&P 500 closed little changed on Friday, a fourth straight day of declines, amid weakness in energy and Walt Disney.

GoPro Hero4 Session gets $100 price cut, Xiaomi Yi launches in US
When GoPro introduced the Session action camera in its Hero4 line, it made the mistake of offering the new model at the same price point as the ...

The North Pole is Back in Session
Santa doesn't spread cheer across the globe all by himself. As soon as the first frost is on the mistletoe, hundreds of helpful elves work day ...

Should We Fear Peak Human?: Master Post for Uncharted 2015 Brad DeLong-Peter Leyden Session
**Jennie Eliot**: Your Uncharted Interview Video: To Brad, Peter.... >All links in one place: >* [Full video with highlights](http://reinven ...

TWIABP filmed a live session video for "I Can Be Afraid of Anything," add 2nd NYC show to tour
photo: TWIABP at LPR in August (more by Mimi Hong) The World Is A Beautiful Place & I Am No Longer Afraid To Die is on tour now supporting this ...

Saturday Sessions: Jeff Lynne of "Jeff Lynne's ELO" plays "Turn to stone" - Videos - CBS News
Jeff Lynne is one of the most influential rock musicians and producers ever, and is now leading a 21st-century version of a hit-making powerhouse. ...

Resources last updated: 12/9/2015 5:55:23 AM