troubleshooting Question

ASP.NET recording user id in SQL Server

Avatar of jzlamal
jzlamalFlag for United States of America asked on
9 Comments1 Solution455 ViewsLast Modified:

I have a simple ASP.NET page that I want to capture the AD account a user is logged in with and record it in a SQL Server database.   I have the following SQLDataSource defined below.   I tried using SUSER_SNAME(), but realized that this only provided the account that I used to establish the database connection and not the AD account.   Is there an easy way to get the AD account and pass it into a Insert Parameter?   Does anyone have an example?


<asp:SqlDataSource ID="insTransaction" runat="server" ConnectionString="<%$ ConnectionStrings:MARTConnectionString %>"
InsertCommand="INSERT INTO TT_TRANS(ProjID, EmpID, TRANDATE, Hours, Description, Billed, CreatedBy) VALUES (@ProjID, @EmpID, @TDate, @Hours,@Desc,'N',SUSER_SNAME() )"

<asp:ControlParameter ControlID="DropDownList2" Name="ProjID" PropertyName="SelectedValue" />
<asp:ControlParameter ControlID="DropDownList1" Name="EmpID" PropertyName="SelectedValue" />
<asp:ControlParameter ControlID="TextBox1" Name="TDate" PropertyName="Text" />
<asp:ControlParameter ControlID="TextBox2" Name="Hours" PropertyName="Text" />
<asp:ControlParameter ControlID="TextBox3" Name="Desc" PropertyName="Text" />

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 9 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros