Showing posts with label username. Show all posts
Showing posts with label username. Show all posts

Thursday, March 29, 2012

newbie: I wonder if this is possible in asp.net 2.0

Hey

asp.net 2.0

As far as I know it's possible to search the users registrered at a asp.net
2.0 web portal using either username or e-mail.

But what about the custom profile properties which can be configured in
web.config? Can they be searched too? I guess it can by using foreach loop
and test the contents on every user object.. but I thought maybe there was a
cleaner and faster way to do it...

Lets say for example these are custom profile settings in web.config. any
suggestion on how to search them? Lets say the search should return all
users containing the phrase "Lets" in lastname? or all users of a specific
gender?
<profile enabled="true">
<properties>
<add name="FirstName" type="string"/>
<add name="LastName" type="string"/>
<add name="Gender" type="string"/>
<add name="BirthDate" type="DateTime"/>
</properties>
</profile>

Best RegardsThis article should help, and even fleshes out some of the sample code
provided by one of the MS people for it:

http://www.eggheadcafe.com/articles/20060731.asp
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
"Jeff" wrote:

Quote:

Originally Posted by

Hey
>
asp.net 2.0
>
As far as I know it's possible to search the users registrered at a asp.net
2.0 web portal using either username or e-mail.
>
But what about the custom profile properties which can be configured in
web.config? Can they be searched too? I guess it can by using foreach loop
and test the contents on every user object.. but I thought maybe there was a
cleaner and faster way to do it...
>
Lets say for example these are custom profile settings in web.config. any
suggestion on how to search them? Lets say the search should return all
users containing the phrase "Lets" in lastname? or all users of a specific
gender?
<profile enabled="true">
<properties>
<add name="FirstName" type="string"/>
<add name="LastName" type="string"/>
<add name="Gender" type="string"/>
<add name="BirthDate" type="DateTime"/>
</properties>
</profile>
>
Best Regards
>
>
>

newbie: I wonder if this is possible in asp.net 2.0

Hey
asp.net 2.0
As far as I know it's possible to search the users registrered at a asp.net
2.0 web portal using either username or e-mail.
But what about the custom profile properties which can be configured in
web.config? Can they be searched too? I guess it can by using foreach loop
and test the contents on every user object.. but I thought maybe there was a
cleaner and faster way to do it...
Lets say for example these are custom profile settings in web.config. any
suggestion on how to search them? Lets say the search should return all
users containing the phrase "Lets" in lastname? or all users of a specific
gender?
<profile enabled="true">
<properties>
<add name="FirstName" type="string"/>
<add name="LastName" type="string"/>
<add name="Gender" type="string"/>
<add name="BirthDate" type="DateTime"/>
</properties>
</profile>
Best RegardsThis article should help, and even fleshes out some of the sample code
provided by one of the MS people for it:
http://www.eggheadcafe.com/articles/20060731.asp
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
"Jeff" wrote:

> Hey
> asp.net 2.0
> As far as I know it's possible to search the users registrered at a asp.ne
t
> 2.0 web portal using either username or e-mail.
> But what about the custom profile properties which can be configured in
> web.config? Can they be searched too? I guess it can by using foreach loop
> and test the contents on every user object.. but I thought maybe there was
a
> cleaner and faster way to do it...
> Lets say for example these are custom profile settings in web.config. any
> suggestion on how to search them? Lets say the search should return all
> users containing the phrase "Lets" in lastname? or all users of a specific
> gender?
> <profile enabled="true">
> <properties>
> <add name="FirstName" type="string"/>
> <add name="LastName" type="string"/>
> <add name="Gender" type="string"/>
> <add name="BirthDate" type="DateTime"/>
> </properties>
> </profile>
> Best Regards
>
>

Monday, March 26, 2012

newbie: Problem getting the querystring!

hey

asp.net 2.0

in the page_load event of a web page I place this code:
NameValueCollection parameters = Request.QueryString;
string username = parameters[0].ToString();

The URL has a querystring, for example like this: Default.aspx?user=newbie

But this code don't get the querystring, the parameters collection gets no
entries from this line "NameValueCollection parameters =
Request.QueryString;"

What am I doing wrong here?

JeffJeff wrote:

Quote:

Originally Posted by

hey
>
asp.net 2.0
>
in the page_load event of a web page I place this code:
NameValueCollection parameters = Request.QueryString;
string username = parameters[0].ToString();
>
The URL has a querystring, for example like this: Default.aspx?user=newbie
>
But this code don't get the querystring, the parameters collection gets no
entries from this line "NameValueCollection parameters =
Request.QueryString;"
>
What am I doing wrong here?
>
Jeff


string username = Request.QueryString["user"];
Best bet is to access the querystring collection directly. I'm not sure if
it's something that can do like this, as normally a lot of collections are
copied using the CopyTo method, but this is usually done for arrays not
specialized collections.

Your best bet though is to access it directly from the querystring. Also,
don't use positional identifiers to determine a parameter, it's too easy to
change the order that things will appear in so it's best to use the keyname
instead. Also, don't forget to test for null first or else it'll bomb out
when you run into a case where it's an empty value, that's the most common
gatcha when using the querystring.

--
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006

"Jeff" <it_consultant1@.hotmail.com.NOSPAMwrote in message
news:udZYNHc%23GHA.4472@.TK2MSFTNGP05.phx.gbl...

Quote:

Originally Posted by

hey
>
asp.net 2.0
>
in the page_load event of a web page I place this code:
NameValueCollection parameters = Request.QueryString;
string username = parameters[0].ToString();
>
The URL has a querystring, for example like this: Default.aspx?user=newbie
>
But this code don't get the querystring, the parameters collection gets no
entries from this line "NameValueCollection parameters =
Request.QueryString;"
>
What am I doing wrong here?
>
Jeff
>


Default.aspx?user=newbie
string username = Request.QueryString["user"]; gives username a NULL
value...

Any more suggestions?

"Simon Rigby" <google@.simonrigby.co.ukwrote in message
news:1161951708.089584.264150@.m7g2000cwm.googlegro ups.com...

Quote:

Originally Posted by

>
Jeff wrote:

Quote:

Originally Posted by

>hey
>>
>asp.net 2.0
>>
>in the page_load event of a web page I place this code:
>NameValueCollection parameters = Request.QueryString;
>string username = parameters[0].ToString();
>>
>The URL has a querystring, for example like this:
>Default.aspx?user=newbie
>>
>But this code don't get the querystring, the parameters collection gets
>no
>entries from this line "NameValueCollection parameters =
>Request.QueryString;"
>>
>What am I doing wrong here?
>>
>Jeff


>
string username = Request.QueryString["user"];
>


"Jeff" <it_consultant1@.hotmail.com.NOSPAMwrote in message
news:udZYNHc%23GHA.4472@.TK2MSFTNGP05.phx.gbl...

Quote:

Originally Posted by

hey
>
asp.net 2.0
>
in the page_load event of a web page I place this code:
NameValueCollection parameters = Request.QueryString;
string username = parameters[0].ToString();
>
The URL has a querystring, for example like this: Default.aspx?user=newbie
>
But this code don't get the querystring, the parameters collection gets no
entries from this line "NameValueCollection parameters =
Request.QueryString;"
>
What am I doing wrong here?
>
Jeff
>


I usually use the form
if Request.QueryString.Item("_o") <string.empty then
stroID = Request.QueryString.Item("_o").tostring()
end if

to get the whole collection you can use

Dim coll As NameValueCollection
coll=request.querystring

and then you can access it using coll("_o") for example

Mike
It's my own fault... I thought the URL had a querystring, but because I had
set a breakpoint and then checked the URL during debug, I didn't see the
real URL, I only saw the last URL....

"Jeff" <it_consultant1@.hotmail.com.NOSPAMwrote in message
news:udZYNHc%23GHA.4472@.TK2MSFTNGP05.phx.gbl...

Quote:

Originally Posted by

hey
>
asp.net 2.0
>
in the page_load event of a web page I place this code:
NameValueCollection parameters = Request.QueryString;
string username = parameters[0].ToString();
>
The URL has a querystring, for example like this: Default.aspx?user=newbie
>
But this code don't get the querystring, the parameters collection gets no
entries from this line "NameValueCollection parameters =
Request.QueryString;"
>
What am I doing wrong here?
>
Jeff
>

newbie: Problem getting the querystring!

hey
asp.net 2.0
in the page_load event of a web page I place this code:
NameValueCollection parameters = Request.QueryString;
string username = parameters[0].ToString();
The URL has a querystring, for example like this: Default.aspx?user=newbie
But this code don't get the querystring, the parameters collection gets no
entries from this line "NameValueCollection parameters =
Request.QueryString;"
What am I doing wrong here?
JeffJeff wrote:
> hey
> asp.net 2.0
> in the page_load event of a web page I place this code:
> NameValueCollection parameters = Request.QueryString;
> string username = parameters[0].ToString();
> The URL has a querystring, for example like this: Default.aspx?user=newbie
> But this code don't get the querystring, the parameters collection gets no
> entries from this line "NameValueCollection parameters =
> Request.QueryString;"
> What am I doing wrong here?
> Jeff
string username = Request.QueryString["user"];
Best bet is to access the querystring collection directly. I'm not sure if
it's something that can do like this, as normally a lot of collections are
copied using the CopyTo method, but this is usually done for arrays not
specialized collections.
Your best bet though is to access it directly from the querystring. Also,
don't use positional identifiers to determine a parameter, it's too easy to
change the order that things will appear in so it's best to use the keyname
instead. Also, don't forget to test for null first or else it'll bomb out
when you run into a case where it's an empty value, that's the most common
gatcha when using the querystring.
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199...2006
"Jeff" <it_consultant1@.hotmail.com.NOSPAM> wrote in message
news:udZYNHc%23GHA.4472@.TK2MSFTNGP05.phx.gbl...
> hey
> asp.net 2.0
> in the page_load event of a web page I place this code:
> NameValueCollection parameters = Request.QueryString;
> string username = parameters[0].ToString();
> The URL has a querystring, for example like this: Default.aspx?user=newbie
> But this code don't get the querystring, the parameters collection gets no
> entries from this line "NameValueCollection parameters =
> Request.QueryString;"
> What am I doing wrong here?
> Jeff
>
Default.aspx?user=newbie
string username = Request.QueryString["user"]; gives username a NULL
value...
Any more suggestions?
"Simon Rigby" <google@.simonrigby.co.uk> wrote in message
news:1161951708.089584.264150@.m7g2000cwm.googlegroups.com...
> Jeff wrote:
> string username = Request.QueryString["user"];
>
"Jeff" <it_consultant1@.hotmail.com.NOSPAM> wrote in message
news:udZYNHc%23GHA.4472@.TK2MSFTNGP05.phx.gbl...
> hey
> asp.net 2.0
> in the page_load event of a web page I place this code:
> NameValueCollection parameters = Request.QueryString;
> string username = parameters[0].ToString();
> The URL has a querystring, for example like this: Default.aspx?user=newbie
> But this code don't get the querystring, the parameters collection gets no
> entries from this line "NameValueCollection parameters =
> Request.QueryString;"
> What am I doing wrong here?
> Jeff
>
I usually use the form
if Request.QueryString.Item("_o") <> string.empty then
stroID = Request.QueryString.Item("_o").tostring()
end if
to get the whole collection you can use
Dim coll As NameValueCollection
coll=request.querystring
and then you can access it using coll("_o") for example
Mike

Newbie: Propably simple answer Checkbox_checked?

Hi there

I what to test a stored procedures on a web page using the normal connection
string.
the controls: Server, username,Password, database allow to select the
appropriate Sql server database.
Now I would use checkbox = Trusted connection as option to logon to the
database.

I guess the question that I have is where am I going wrong in the code?
How can I step through the script before or up until the page is loaded?

Any hints are greatly appreciated, the same will be made available after
completion.

Regards

Norman

Here is the Code:-----------------
<%@dotnet.itags.org. Page Language="VB" AutoEventWireup="True" %>
<%@dotnet.itags.org. import Namespace="System.Data" %>
<%@dotnet.itags.org. import Namespace="System.Data.SqlClient" %>
<%@dotnet.itags.org. import Namespace="System.Web.UI.WebControls" %>
<HTML>
<HEAD>
<script runat="server"
' code to check if the tickbox was ticked

Sub Check_Clicked(sender As Object, e As EventArgs)

If WinTrusted.checked then
'Dim conn As New SqlConnection( _
' "Data source=" & DatabaseServer.Text & _
' ";Trusted_Connection=true" & _
' ";Initial catalog=" & Database.Text)
'else
'Dim conn As New SqlConnection( _
' "Data source=" & DatabaseServer.Text & _
' ";Trusted_Connection=true" & _
' ";Initial catalog=" & Database.Text)
end if
End Sub
'
Sub LoginButton_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim ds As New DataSet
Dim conn As New SqlConnection( _
"Data source=" & DatabaseServer.Text & _
";Trusted_Connection=true" & _
";Initial catalog=" & Database.Text)

Dim cmd As New SqlCommand("sp_stored_procedures", conn) ' << when Sub
Check_Clicked and the code is run Asp courses an error at this line saying
that "conn" is not defined??
Dim adpt As New SqlDataAdapter(cmd)
Try
Status.Text = ""
adpt.Fill(ds, "SPs")
SPs.DataSource = ds.Tables("SPs")
SPs.DataTextField = "PROCEDURE_NAME"
SPs.DataBind()
Catch ex As SqlException
Status.Text = ex.Message
End Try
End Sub
Sub GetParametersButton_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim ds As New DataSet
'If Wintrusted.checked = True Then
' Dim conn As New SqlConnection( _
' "Data source=" & DatabaseServer.Text & _
' ";Trusted_Connection=true" & _
' ";Initial catalog=" & Database.Text)
'Else
Dim conn As New SqlConnection( _
"Data source=" & DatabaseServer.Text & _
";User id=" & Userid.text & _
";Password=" & Password.Text & _
";Initial catalog=" & Database.Text)
'End If
Dim cmd As New SqlCommand("sp_sproc_columns", conn) '' << when Sub
Check_Clicked and the code is run Asp courses an error at this line saying
that "conn" is not defined??
Dim adpt As New SqlDataAdapter(cmd)
Try
Status.Text = ""
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@dotnet.itags.org.procedure_name", SqlDbType.NVarchar, 390).Value = _
SPs.SelectedItem.Value
adpt.Fill(ds, "Parameters")
ParametersDataGrid.DataSource = ds.Tables("Parameters")
ParametersDataGrid.DataBind()
ResultsDataGrid.Visible = False
Catch ex As SqlException
Status.Text = ex.Message
End Try
End Sub

Sub AddParameters(ByVal cmd As SqlCommand)
'works ok
End Sub

Sub UpdateParameters(ByVal cmd As SqlCommand)
'Works Ok
End Sub

Sub ExecuteQueryButton_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim ds As New DataSet
'If WinTrusted.checked then
'Dim conn As New SqlConnection( _
' "Data source=" & DatabaseServer.Text & _
' ";Trusted_Connection=true" & _
' ";Initial catalog=" & Database.Text)
'else
Dim conn As New SqlConnection( _
"Data source=" & DatabaseServer.Text & _
";Trusted_Connection=true" & _
";Initial catalog=" & Database.Text)
'end if
Dim cmd As New SqlCommand(SPs.SelectedItem.Value, conn) ' ' << when Sub
Check_Clicked and the code is run Asp courses an error at this line saying
that "conn" is not defined??
Dim adpt As New SqlDataAdapter(cmd)
Try
Status.Text = ""
cmd.CommandType = CommandType.StoredProcedure
AddParameters(cmd)
adpt.Fill(ds, "Results")
UpdateParameters(cmd)
ResultsDataGrid.DataSource = ds.Tables("Results")
ResultsDataGrid.DataBind()
ResultsDataGrid.Visible = True
Catch ex As SqlException
Status.Text = ex.Message
End Try
End Sub
</script>
</HEAD>
----------End of
Code--------------You problem i think is happening because you are defining the connection in
a if statement
that would make it a local variable of
if(conditional statement)
{
// you code and your variables.
// any variables declared here are local to this if statement..
}

try
SqlConnection conn;
if(WinTrusted.checked == true)
con = new SqlConnection("con paramas")
else
con = new SqlConnection("second set of param")
}
SqlDataAdapter myCommand = new SqlDataAdapter("sp_storedproc", myCon)
myCommand.SelectCommand.CommandType = CommandType.StoredProc

This should work,

Hermit Dave

"Norman Fritag" <mtp.net@.ozemail.com.au> wrote in message
news:cY6Cb.10$Tq.1083@.nnrp1.ozemail.com.au...
> Hi there
> I what to test a stored procedures on a web page using the normal
connection
> string.
> the controls: Server, username,Password, database allow to select the
> appropriate Sql server database.
> Now I would use checkbox = Trusted connection as option to logon to the
> database.
> I guess the question that I have is where am I going wrong in the code?
> How can I step through the script before or up until the page is loaded?
> Any hints are greatly appreciated, the same will be made available after
> completion.
> Regards
> Norman
>
> Here is the Code:-----------------
> <%@. Page Language="VB" AutoEventWireup="True" %>
> <%@. import Namespace="System.Data" %>
> <%@. import Namespace="System.Data.SqlClient" %>
> <%@. import Namespace="System.Web.UI.WebControls" %>
> <HTML>
> <HEAD>
> <script runat="server">
> ' code to check if the tickbox was ticked
> Sub Check_Clicked(sender As Object, e As EventArgs)
> If WinTrusted.checked then
> 'Dim conn As New SqlConnection( _
> ' "Data source=" & DatabaseServer.Text & _
> ' ";Trusted_Connection=true" & _
> ' ";Initial catalog=" & Database.Text)
> 'else
> 'Dim conn As New SqlConnection( _
> ' "Data source=" & DatabaseServer.Text & _
> ' ";Trusted_Connection=true" & _
> ' ";Initial catalog=" & Database.Text)
> end if
> End Sub
> '
> Sub LoginButton_Click(ByVal sender As Object, ByVal e As EventArgs)
> Dim ds As New DataSet
> Dim conn As New SqlConnection( _
> "Data source=" & DatabaseServer.Text & _
> ";Trusted_Connection=true" & _
> ";Initial catalog=" & Database.Text)
> Dim cmd As New SqlCommand("sp_stored_procedures", conn) ' << when Sub
> Check_Clicked and the code is run Asp courses an error at this line saying
> that "conn" is not defined??
> Dim adpt As New SqlDataAdapter(cmd)
> Try
> Status.Text = ""
> adpt.Fill(ds, "SPs")
> SPs.DataSource = ds.Tables("SPs")
> SPs.DataTextField = "PROCEDURE_NAME"
> SPs.DataBind()
> Catch ex As SqlException
> Status.Text = ex.Message
> End Try
> End Sub
> Sub GetParametersButton_Click(ByVal sender As Object, ByVal e As
EventArgs)
> Dim ds As New DataSet
> 'If Wintrusted.checked = True Then
> ' Dim conn As New SqlConnection( _
> ' "Data source=" & DatabaseServer.Text & _
> ' ";Trusted_Connection=true" & _
> ' ";Initial catalog=" & Database.Text)
> 'Else
> Dim conn As New SqlConnection( _
> "Data source=" & DatabaseServer.Text & _
> ";User id=" & Userid.text & _
> ";Password=" & Password.Text & _
> ";Initial catalog=" & Database.Text)
> 'End If
> Dim cmd As New SqlCommand("sp_sproc_columns", conn) '' << when Sub
> Check_Clicked and the code is run Asp courses an error at this line saying
> that "conn" is not defined??
> Dim adpt As New SqlDataAdapter(cmd)
> Try
> Status.Text = ""
> cmd.CommandType = CommandType.StoredProcedure
> cmd.Parameters.Add("@.procedure_name", SqlDbType.NVarchar, 390).Value = _
> SPs.SelectedItem.Value
> adpt.Fill(ds, "Parameters")
> ParametersDataGrid.DataSource = ds.Tables("Parameters")
> ParametersDataGrid.DataBind()
> ResultsDataGrid.Visible = False
> Catch ex As SqlException
> Status.Text = ex.Message
> End Try
> End Sub
> Sub AddParameters(ByVal cmd As SqlCommand)
> 'works ok
> End Sub
> Sub UpdateParameters(ByVal cmd As SqlCommand)
> 'Works Ok
> End Sub
> Sub ExecuteQueryButton_Click(ByVal sender As Object, ByVal e As EventArgs)
> Dim ds As New DataSet
> 'If WinTrusted.checked then
> 'Dim conn As New SqlConnection( _
> ' "Data source=" & DatabaseServer.Text & _
> ' ";Trusted_Connection=true" & _
> ' ";Initial catalog=" & Database.Text)
> 'else
> Dim conn As New SqlConnection( _
> "Data source=" & DatabaseServer.Text & _
> ";Trusted_Connection=true" & _
> ";Initial catalog=" & Database.Text)
> 'end if
> Dim cmd As New SqlCommand(SPs.SelectedItem.Value, conn) ' ' << when Sub
> Check_Clicked and the code is run Asp courses an error at this line saying
> that "conn" is not defined??
> Dim adpt As New SqlDataAdapter(cmd)
> Try
> Status.Text = ""
> cmd.CommandType = CommandType.StoredProcedure
> AddParameters(cmd)
> adpt.Fill(ds, "Results")
> UpdateParameters(cmd)
> ResultsDataGrid.DataSource = ds.Tables("Results")
> ResultsDataGrid.DataBind()
> ResultsDataGrid.Visible = True
> Catch ex As SqlException
> Status.Text = ex.Message
> End Try
> End Sub
> </script>
> </HEAD>
> ----------End of
> Code--------------
Sorry bout the typos... too knackered... and too hungry and i would do with
some food and some sleep...

Your problem i think is happening because you are defining the connection in
a if statement
that would make it a local variable of
if(conditional statement)
{
// you code and your variables.
// any variables declared here are local to this if statement..
}

try
SqlConnection conn;
if(WinTrusted.checked == true)
conn = new SqlConnection("con paramas")
else
conn = new SqlConnection("second set of param")
}
SqlDataAdapter myCommand = new SqlDataAdapter("sp_storedproc", conn)
myCommand.SelectCommand.CommandType = CommandType.StoredProc

This should work,

Hermit Dave

"Hermit Dave" <hermitd.REMOVE@.CAPS.AND.DOTS.hotmail.com> wrote in message
news:evdi6$DwDHA.2372@.TK2MSFTNGP09.phx.gbl...
> You problem i think is happening because you are defining the connection
in
> a if statement
> that would make it a local variable of
> if(conditional statement)
> {
> // you code and your variables.
> // any variables declared here are local to this if statement..
> }
> try
> SqlConnection conn;
> if(WinTrusted.checked == true)
> con = new SqlConnection("con paramas")
> else
> con = new SqlConnection("second set of param")
> }
> SqlDataAdapter myCommand = new SqlDataAdapter("sp_storedproc", myCon)
> myCommand.SelectCommand.CommandType = CommandType.StoredProc
> This should work,
> Hermit Dave
> "Norman Fritag" <mtp.net@.ozemail.com.au> wrote in message
> news:cY6Cb.10$Tq.1083@.nnrp1.ozemail.com.au...
> > Hi there
> > I what to test a stored procedures on a web page using the normal
> connection
> > string.
> > the controls: Server, username,Password, database allow to select the
> > appropriate Sql server database.
> > Now I would use checkbox = Trusted connection as option to logon to the
> > database.
> > I guess the question that I have is where am I going wrong in the code?
> > How can I step through the script before or up until the page is loaded?
> > Any hints are greatly appreciated, the same will be made available after
> > completion.
> > Regards
> > Norman
> > Here is the Code:-----------------
> > <%@. Page Language="VB" AutoEventWireup="True" %>
> > <%@. import Namespace="System.Data" %>
> > <%@. import Namespace="System.Data.SqlClient" %>
> > <%@. import Namespace="System.Web.UI.WebControls" %>
> > <HTML>
> > <HEAD>
> > <script runat="server">
> > ' code to check if the tickbox was ticked
> > Sub Check_Clicked(sender As Object, e As EventArgs)
> > If WinTrusted.checked then
> > 'Dim conn As New SqlConnection( _
> > ' "Data source=" & DatabaseServer.Text & _
> > ' ";Trusted_Connection=true" & _
> > ' ";Initial catalog=" & Database.Text)
> > 'else
> > 'Dim conn As New SqlConnection( _
> > ' "Data source=" & DatabaseServer.Text & _
> > ' ";Trusted_Connection=true" & _
> > ' ";Initial catalog=" & Database.Text)
> > end if
> > End Sub
> > '
> > Sub LoginButton_Click(ByVal sender As Object, ByVal e As EventArgs)
> > Dim ds As New DataSet
> > Dim conn As New SqlConnection( _
> > "Data source=" & DatabaseServer.Text & _
> > ";Trusted_Connection=true" & _
> > ";Initial catalog=" & Database.Text)
> > Dim cmd As New SqlCommand("sp_stored_procedures", conn) ' << when Sub
> > Check_Clicked and the code is run Asp courses an error at this line
saying
> > that "conn" is not defined??
> > Dim adpt As New SqlDataAdapter(cmd)
> > Try
> > Status.Text = ""
> > adpt.Fill(ds, "SPs")
> > SPs.DataSource = ds.Tables("SPs")
> > SPs.DataTextField = "PROCEDURE_NAME"
> > SPs.DataBind()
> > Catch ex As SqlException
> > Status.Text = ex.Message
> > End Try
> > End Sub
> > Sub GetParametersButton_Click(ByVal sender As Object, ByVal e As
> EventArgs)
> > Dim ds As New DataSet
> > 'If Wintrusted.checked = True Then
> > ' Dim conn As New SqlConnection( _
> > ' "Data source=" & DatabaseServer.Text & _
> > ' ";Trusted_Connection=true" & _
> > ' ";Initial catalog=" & Database.Text)
> > 'Else
> > Dim conn As New SqlConnection( _
> > "Data source=" & DatabaseServer.Text & _
> > ";User id=" & Userid.text & _
> > ";Password=" & Password.Text & _
> > ";Initial catalog=" & Database.Text)
> > 'End If
> > Dim cmd As New SqlCommand("sp_sproc_columns", conn) '' << when Sub
> > Check_Clicked and the code is run Asp courses an error at this line
saying
> > that "conn" is not defined??
> > Dim adpt As New SqlDataAdapter(cmd)
> > Try
> > Status.Text = ""
> > cmd.CommandType = CommandType.StoredProcedure
> > cmd.Parameters.Add("@.procedure_name", SqlDbType.NVarchar, 390).Value = _
> > SPs.SelectedItem.Value
> > adpt.Fill(ds, "Parameters")
> > ParametersDataGrid.DataSource = ds.Tables("Parameters")
> > ParametersDataGrid.DataBind()
> > ResultsDataGrid.Visible = False
> > Catch ex As SqlException
> > Status.Text = ex.Message
> > End Try
> > End Sub
> > Sub AddParameters(ByVal cmd As SqlCommand)
> > 'works ok
> > End Sub
> > Sub UpdateParameters(ByVal cmd As SqlCommand)
> > 'Works Ok
> > End Sub
> > Sub ExecuteQueryButton_Click(ByVal sender As Object, ByVal e As
EventArgs)
> > Dim ds As New DataSet
> > 'If WinTrusted.checked then
> > 'Dim conn As New SqlConnection( _
> > ' "Data source=" & DatabaseServer.Text & _
> > ' ";Trusted_Connection=true" & _
> > ' ";Initial catalog=" & Database.Text)
> > 'else
> > Dim conn As New SqlConnection( _
> > "Data source=" & DatabaseServer.Text & _
> > ";Trusted_Connection=true" & _
> > ";Initial catalog=" & Database.Text)
> > 'end if
> > Dim cmd As New SqlCommand(SPs.SelectedItem.Value, conn) ' ' << when Sub
> > Check_Clicked and the code is run Asp courses an error at this line
saying
> > that "conn" is not defined??
> > Dim adpt As New SqlDataAdapter(cmd)
> > Try
> > Status.Text = ""
> > cmd.CommandType = CommandType.StoredProcedure
> > AddParameters(cmd)
> > adpt.Fill(ds, "Results")
> > UpdateParameters(cmd)
> > ResultsDataGrid.DataSource = ds.Tables("Results")
> > ResultsDataGrid.DataBind()
> > ResultsDataGrid.Visible = True
> > Catch ex As SqlException
> > Status.Text = ex.Message
> > End Try
> > End Sub
> > </script>
> > </HEAD>
> > ----------End of
> > Code--------------
Thanks Hermit Dave
I picked up the thought an it works Ok.
Regards

Norman

"Hermit Dave" <hermitd.REMOVE@.CAPS.AND.DOTS.hotmail.com> wrote in message
news:evdi6$DwDHA.2372@.TK2MSFTNGP09.phx.gbl...
> You problem i think is happening because you are defining the connection
in
> a if statement
> that would make it a local variable of
> if(conditional statement)
> {
> // you code and your variables.
> // any variables declared here are local to this if statement..
> }
> try
> SqlConnection conn;
> if(WinTrusted.checked == true)
> con = new SqlConnection("con paramas")
> else
> con = new SqlConnection("second set of param")
> }
> SqlDataAdapter myCommand = new SqlDataAdapter("sp_storedproc", myCon)
> myCommand.SelectCommand.CommandType = CommandType.StoredProc
> This should work,
> Hermit Dave
> "Norman Fritag" <mtp.net@.ozemail.com.au> wrote in message
> news:cY6Cb.10$Tq.1083@.nnrp1.ozemail.com.au...
> > Hi there
> > I what to test a stored procedures on a web page using the normal
> connection
> > string.
> > the controls: Server, username,Password, database allow to select the
> > appropriate Sql server database.
> > Now I would use checkbox = Trusted connection as option to logon to the
> > database.
> > I guess the question that I have is where am I going wrong in the code?
> > How can I step through the script before or up until the page is loaded?
> > Any hints are greatly appreciated, the same will be made available after
> > completion.
> > Regards
> > Norman
> > Here is the Code:-----------------
> > <%@. Page Language="VB" AutoEventWireup="True" %>
> > <%@. import Namespace="System.Data" %>
> > <%@. import Namespace="System.Data.SqlClient" %>
> > <%@. import Namespace="System.Web.UI.WebControls" %>
> > <HTML>
> > <HEAD>
> > <script runat="server">
> > ' code to check if the tickbox was ticked
> > Sub Check_Clicked(sender As Object, e As EventArgs)
> > If WinTrusted.checked then
> > 'Dim conn As New SqlConnection( _
> > ' "Data source=" & DatabaseServer.Text & _
> > ' ";Trusted_Connection=true" & _
> > ' ";Initial catalog=" & Database.Text)
> > 'else
> > 'Dim conn As New SqlConnection( _
> > ' "Data source=" & DatabaseServer.Text & _
> > ' ";Trusted_Connection=true" & _
> > ' ";Initial catalog=" & Database.Text)
> > end if
> > End Sub
> > '
> > Sub LoginButton_Click(ByVal sender As Object, ByVal e As EventArgs)
> > Dim ds As New DataSet
> > Dim conn As New SqlConnection( _
> > "Data source=" & DatabaseServer.Text & _
> > ";Trusted_Connection=true" & _
> > ";Initial catalog=" & Database.Text)
> > Dim cmd As New SqlCommand("sp_stored_procedures", conn) ' << when Sub
> > Check_Clicked and the code is run Asp courses an error at this line
saying
> > that "conn" is not defined??
> > Dim adpt As New SqlDataAdapter(cmd)
> > Try
> > Status.Text = ""
> > adpt.Fill(ds, "SPs")
> > SPs.DataSource = ds.Tables("SPs")
> > SPs.DataTextField = "PROCEDURE_NAME"
> > SPs.DataBind()
> > Catch ex As SqlException
> > Status.Text = ex.Message
> > End Try
> > End Sub
> > Sub GetParametersButton_Click(ByVal sender As Object, ByVal e As
> EventArgs)
> > Dim ds As New DataSet
> > 'If Wintrusted.checked = True Then
> > ' Dim conn As New SqlConnection( _
> > ' "Data source=" & DatabaseServer.Text & _
> > ' ";Trusted_Connection=true" & _
> > ' ";Initial catalog=" & Database.Text)
> > 'Else
> > Dim conn As New SqlConnection( _
> > "Data source=" & DatabaseServer.Text & _
> > ";User id=" & Userid.text & _
> > ";Password=" & Password.Text & _
> > ";Initial catalog=" & Database.Text)
> > 'End If
> > Dim cmd As New SqlCommand("sp_sproc_columns", conn) '' << when Sub
> > Check_Clicked and the code is run Asp courses an error at this line
saying
> > that "conn" is not defined??
> > Dim adpt As New SqlDataAdapter(cmd)
> > Try
> > Status.Text = ""
> > cmd.CommandType = CommandType.StoredProcedure
> > cmd.Parameters.Add("@.procedure_name", SqlDbType.NVarchar, 390).Value = _
> > SPs.SelectedItem.Value
> > adpt.Fill(ds, "Parameters")
> > ParametersDataGrid.DataSource = ds.Tables("Parameters")
> > ParametersDataGrid.DataBind()
> > ResultsDataGrid.Visible = False
> > Catch ex As SqlException
> > Status.Text = ex.Message
> > End Try
> > End Sub
> > Sub AddParameters(ByVal cmd As SqlCommand)
> > 'works ok
> > End Sub
> > Sub UpdateParameters(ByVal cmd As SqlCommand)
> > 'Works Ok
> > End Sub
> > Sub ExecuteQueryButton_Click(ByVal sender As Object, ByVal e As
EventArgs)
> > Dim ds As New DataSet
> > 'If WinTrusted.checked then
> > 'Dim conn As New SqlConnection( _
> > ' "Data source=" & DatabaseServer.Text & _
> > ' ";Trusted_Connection=true" & _
> > ' ";Initial catalog=" & Database.Text)
> > 'else
> > Dim conn As New SqlConnection( _
> > "Data source=" & DatabaseServer.Text & _
> > ";Trusted_Connection=true" & _
> > ";Initial catalog=" & Database.Text)
> > 'end if
> > Dim cmd As New SqlCommand(SPs.SelectedItem.Value, conn) ' ' << when Sub
> > Check_Clicked and the code is run Asp courses an error at this line
saying
> > that "conn" is not defined??
> > Dim adpt As New SqlDataAdapter(cmd)
> > Try
> > Status.Text = ""
> > cmd.CommandType = CommandType.StoredProcedure
> > AddParameters(cmd)
> > adpt.Fill(ds, "Results")
> > UpdateParameters(cmd)
> > ResultsDataGrid.DataSource = ds.Tables("Results")
> > ResultsDataGrid.DataBind()
> > ResultsDataGrid.Visible = True
> > Catch ex As SqlException
> > Status.Text = ex.Message
> > End Try
> > End Sub
> > </script>
> > </HEAD>
> > ----------End of
> > Code--------------

Thursday, March 22, 2012

newboe: how to get the user name?

OS: XP pro
IDE VS 2005 .NET
ASP.NET 2.0
System.Security.AccessControl.SecurityInfos.Owner.ToString() returns
domain\username...if the domain is named "TEST" and username is "per" then
this statement returns TEST\per...
But what code must I do if I went to the fullname of the user?
JeffAsk the user to put it into a form. ;-)
Seriously, though, if the user is logged in to Active Directory, you should
be able to use the System.DirectoryServices namespace and classes to query
the Active Directory for this information.
HTH,
Kevin Spencer
Microsoft MVP
Professional Numbskull
Hard work is a medication for which
there is no placebo.
"Jeff" <it_consultant1@.hotmail.com.NOSPAM> wrote in message
news:un2nKgZeGHA.564@.TK2MSFTNGP02.phx.gbl...
> OS: XP pro
> IDE VS 2005 .NET
> ASP.NET 2.0
> System.Security.AccessControl.SecurityInfos.Owner.ToString() returns
> domain\username...if the domain is named "TEST" and username is "per" then
> this statement returns TEST\per...
> But what code must I do if I went to the fullname of the user?
> Jeff
>
Thanks, I'm looking into it now:
System.DirectoryServices.DirectoryEntry de = new
System.DirectoryServices.DirectoryEntry();
string fullname = de.Properties["displayName"].Value.ToString();
This code isn't working because I need to set the de.Path property before
executing the last line.. I'm not sure how to get the domain name the user
is logged into...Any tips would be great...
I've tryed, with out luck using this statment:
string domain = de.Properties["defaultNamingContext"][0];
This statement gives me an error message saying "This domain do not exist"
(or something like that, the error message I get on my computer is in
Norwegian and I translated it into English... I'm a native Norwegian)
What am I doing wrong here?
Any tips would be received with great appreciation!
Jeff
"Kevin Spencer" <kevin@.DIESPAMMERSDIEtakempis.com> wrote in message
news:uKn1CxZeGHA.5012@.TK2MSFTNGP05.phx.gbl...
> Ask the user to put it into a form. ;-)
> Seriously, though, if the user is logged in to Active Directory, you
> should be able to use the System.DirectoryServices namespace and classes
> to query the Active Directory for this information.
> --
> HTH,
> Kevin Spencer
> Microsoft MVP
> Professional Numbskull
> Hard work is a medication for which
> there is no placebo.
> "Jeff" <it_consultant1@.hotmail.com.NOSPAM> wrote in message
> news:un2nKgZeGHA.564@.TK2MSFTNGP02.phx.gbl...
>
Your app will only be able to get AD information about the domain it belongs
to.
HTH,
Kevin Spencer
Microsoft MVP
Professional Numbskull
Hard work is a medication for which
there is no placebo.
"Jeff" <it_consultant1@.hotmail.com.NOSPAM> wrote in message
news:%23hChlzaeGHA.3888@.TK2MSFTNGP02.phx.gbl...
> Thanks, I'm looking into it now:
> System.DirectoryServices.DirectoryEntry de = new
> System.DirectoryServices.DirectoryEntry();
> string fullname = de.Properties["displayName"].Value.ToString();
> This code isn't working because I need to set the de.Path property before
> executing the last line.. I'm not sure how to get the domain name the user
> is logged into...Any tips would be great...
> I've tryed, with out luck using this statment:
> string domain = de.Properties["defaultNamingContext"][0];
> This statement gives me an error message saying "This domain do not exist"
> (or something like that, the error message I get on my computer is in
> Norwegian and I translated it into English... I'm a native Norwegian)
> What am I doing wrong here?
> Any tips would be received with great appreciation!
> Jeff
>
> "Kevin Spencer" <kevin@.DIESPAMMERSDIEtakempis.com> wrote in message
> news:uKn1CxZeGHA.5012@.TK2MSFTNGP05.phx.gbl...
>

newboe: how to get the user name?

OS: XP pro
IDE VS 2005 .NET
ASP.NET 2.0

System.Security.AccessControl.SecurityInfos.Owner. ToString() returns
domain\username...if the domain is named "TEST" and username is "per" then
this statement returns TEST\per...

But what code must I do if I went to the fullname of the user?

JeffAsk the user to put it into a form. ;-)

Seriously, though, if the user is logged in to Active Directory, you should
be able to use the System.DirectoryServices namespace and classes to query
the Active Directory for this information.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

"Jeff" <it_consultant1@.hotmail.com.NOSPAM> wrote in message
news:un2nKgZeGHA.564@.TK2MSFTNGP02.phx.gbl...
> OS: XP pro
> IDE VS 2005 .NET
> ASP.NET 2.0
> System.Security.AccessControl.SecurityInfos.Owner. ToString() returns
> domain\username...if the domain is named "TEST" and username is "per" then
> this statement returns TEST\per...
> But what code must I do if I went to the fullname of the user?
> Jeff
Thanks, I'm looking into it now:

System.DirectoryServices.DirectoryEntry de = new
System.DirectoryServices.DirectoryEntry();
string fullname = de.Properties["displayName"].Value.ToString();

This code isn't working because I need to set the de.Path property before
executing the last line.. I'm not sure how to get the domain name the user
is logged into...Any tips would be great...

I've tryed, with out luck using this statment:
string domain = de.Properties["defaultNamingContext"][0];
This statement gives me an error message saying "This domain do not exist"
(or something like that, the error message I get on my computer is in
Norwegian and I translated it into English... I'm a native Norwegian)

What am I doing wrong here?

Any tips would be received with great appreciation!

Jeff

"Kevin Spencer" <kevin@.DIESPAMMERSDIEtakempis.com> wrote in message
news:uKn1CxZeGHA.5012@.TK2MSFTNGP05.phx.gbl...
> Ask the user to put it into a form. ;-)
> Seriously, though, if the user is logged in to Active Directory, you
> should be able to use the System.DirectoryServices namespace and classes
> to query the Active Directory for this information.
> --
> HTH,
> Kevin Spencer
> Microsoft MVP
> Professional Numbskull
> Hard work is a medication for which
> there is no placebo.
> "Jeff" <it_consultant1@.hotmail.com.NOSPAM> wrote in message
> news:un2nKgZeGHA.564@.TK2MSFTNGP02.phx.gbl...
>> OS: XP pro
>> IDE VS 2005 .NET
>> ASP.NET 2.0
>>
>> System.Security.AccessControl.SecurityInfos.Owner. ToString() returns
>> domain\username...if the domain is named "TEST" and username is "per"
>> then this statement returns TEST\per...
>>
>> But what code must I do if I went to the fullname of the user?
>>
>> Jeff
>>
Your app will only be able to get AD information about the domain it belongs
to.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.

"Jeff" <it_consultant1@.hotmail.com.NOSPAM> wrote in message
news:%23hChlzaeGHA.3888@.TK2MSFTNGP02.phx.gbl...
> Thanks, I'm looking into it now:
> System.DirectoryServices.DirectoryEntry de = new
> System.DirectoryServices.DirectoryEntry();
> string fullname = de.Properties["displayName"].Value.ToString();
> This code isn't working because I need to set the de.Path property before
> executing the last line.. I'm not sure how to get the domain name the user
> is logged into...Any tips would be great...
> I've tryed, with out luck using this statment:
> string domain = de.Properties["defaultNamingContext"][0];
> This statement gives me an error message saying "This domain do not exist"
> (or something like that, the error message I get on my computer is in
> Norwegian and I translated it into English... I'm a native Norwegian)
> What am I doing wrong here?
> Any tips would be received with great appreciation!
> Jeff
>
> "Kevin Spencer" <kevin@.DIESPAMMERSDIEtakempis.com> wrote in message
> news:uKn1CxZeGHA.5012@.TK2MSFTNGP05.phx.gbl...
>> Ask the user to put it into a form. ;-)
>>
>> Seriously, though, if the user is logged in to Active Directory, you
>> should be able to use the System.DirectoryServices namespace and classes
>> to query the Active Directory for this information.
>>
>> --
>> HTH,
>>
>> Kevin Spencer
>> Microsoft MVP
>> Professional Numbskull
>>
>> Hard work is a medication for which
>> there is no placebo.
>>
>> "Jeff" <it_consultant1@.hotmail.com.NOSPAM> wrote in message
>> news:un2nKgZeGHA.564@.TK2MSFTNGP02.phx.gbl...
>>> OS: XP pro
>>> IDE VS 2005 .NET
>>> ASP.NET 2.0
>>>
>>> System.Security.AccessControl.SecurityInfos.Owner. ToString() returns
>>> domain\username...if the domain is named "TEST" and username is "per"
>>> then this statement returns TEST\per...
>>>
>>> But what code must I do if I went to the fullname of the user?
>>>
>>> Jeff
>>>
>>
>>