Showing posts with label trouble. Show all posts
Showing posts with label trouble. Show all posts

Saturday, March 31, 2012

Trouble authenticating to Remote SQL Server

Ok everyone, i have been pulling my hair out on this one. I have been
working on it for 3 days with no sucess. This problem is occuring at home
where i am running a workgroup. I have Windows 2003 Ent Server on one
machine and windows xp sp2 on another. The db server is located on the
Windows 2003 machine. I am working locally with asp.net 1.1 on the xp
workstation and the web server is also locally on the xp workstation. Every
time i try to connect with the asp.net application to the database i get the
following error:

Server Error in '/WebApplication1' Application.
-----------------------
--

Login failed for user '(null)'. Reason: Not associated with a trusted SQL
Server connection.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Login failed for user
'(null)'. Reason: Not associated with a trusted SQL Server connection.

Source Error:

Line 44:
Line 45: ' fill the dataset
Line 46: dataAdapter.Fill(ds, "Customers")
Line 47: Dim bldr As New SqlCommandBuilder(dataAdapter)
Line 48:

Source File: c:\inetpub\wwwroot\WebApplication1\WebForm1.aspx.v b Line: 46

Stack Trace:

[SqlException: Login failed for user '(null)'. Reason: Not associated with a
trusted SQL Server connection.]
System.Data.SqlClient.ConnectionPool.GetConnection (Boolean&
isInTransaction)

System.Data.SqlClient.SqlConnectionPoolManager.Get PooledConnection(SqlConnec
tionString options, Boolean& isInTransaction)
System.Data.SqlClient.SqlConnection.Open()
System.Data.Common.DbDataAdapter.QuietOpen(IDbConn ection connection,
ConnectionState& originalState)
System.Data.Common.DbDataAdapter.FillFromCommand(O bject data, Int32
startRecord, Int32 maxRecords, String srcTable, IDbCommand command,
CommandBehavior behavior)
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord,
Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior
behavior)
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable)
WebApplication1.WebForm1.Page_Load(Object sender, EventArgs e) in
c:\inetpub\wwwroot\WebApplication1\WebForm1.aspx.v b:46
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()

I have tried to following to fix the problem.

1) Tried to add the asp.net user to sql server

2) Removed tcp/ip from the connect types to sql server

3) added a new user which i called "aspnetuser" to both computers then when
into anonymous logins on IIS and added this user as the anonymous login user
and unchecked the let IIS control the password and typed in the correct
password.

4) change the asp.net user that the install of vs.net added and added them
to the admin group on both machines. I have no problem login into sql server
(windows authentication) when i use my local account i created on the xp
workstation for me (im in the admin group).

The only thing i have not used is impersonation and id rather not unless i
have to. Course since i haven't tried it, i might have trouble with it too.

Scratch what i just said above. I tried impersonaltion and it worked but id
rather not use this if at all possible. I want to use the security that
vs.net set up for the "asp.net" user. Is this possible without using
impersonation?

Thanks,
BrentWhat does your connection string look like? If you are on a workgroup and
NOT in a domain your sql server is not going to know the requesting user.

Have you tried not using a trusted connection and use something like this in
your connection string:

Server=(local);Initial Catalog=pubs;User Id=sa;Password=

-Rob

"Brent Waldrop" <brentwa@.spam.hotmail.com> wrote in message
news:uUMCZ1V0EHA.3236@.TK2MSFTNGP15.phx.gbl...
> Ok everyone, i have been pulling my hair out on this one. I have been
> working on it for 3 days with no sucess. This problem is occuring at home
> where i am running a workgroup. I have Windows 2003 Ent Server on one
> machine and windows xp sp2 on another. The db server is located on the
> Windows 2003 machine. I am working locally with asp.net 1.1 on the xp
> workstation and the web server is also locally on the xp workstation.
> Every
> time i try to connect with the asp.net application to the database i get
> the
> following error:
> Server Error in '/WebApplication1' Application.
> -----------------------
> --
> Login failed for user '(null)'. Reason: Not associated with a trusted SQL
> Server connection.
> Description: An unhandled exception occurred during the execution of the
> current web request. Please review the stack trace for more information
> about the error and where it originated in the code.
> Exception Details: System.Data.SqlClient.SqlException: Login failed for
> user
> '(null)'. Reason: Not associated with a trusted SQL Server connection.
> Source Error:
>
> Line 44:
> Line 45: ' fill the dataset
> Line 46: dataAdapter.Fill(ds, "Customers")
> Line 47: Dim bldr As New SqlCommandBuilder(dataAdapter)
> Line 48:
>
> Source File: c:\inetpub\wwwroot\WebApplication1\WebForm1.aspx.v b Line:
> 46
> Stack Trace:
>
> [SqlException: Login failed for user '(null)'. Reason: Not associated with
> a
> trusted SQL Server connection.]
> System.Data.SqlClient.ConnectionPool.GetConnection (Boolean&
> isInTransaction)
> System.Data.SqlClient.SqlConnectionPoolManager.Get PooledConnection(SqlConnec
> tionString options, Boolean& isInTransaction)
> System.Data.SqlClient.SqlConnection.Open()
> System.Data.Common.DbDataAdapter.QuietOpen(IDbConn ection connection,
> ConnectionState& originalState)
> System.Data.Common.DbDataAdapter.FillFromCommand(O bject data, Int32
> startRecord, Int32 maxRecords, String srcTable, IDbCommand command,
> CommandBehavior behavior)
> System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32
> startRecord,
> Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior
> behavior)
> System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable)
> WebApplication1.WebForm1.Page_Load(Object sender, EventArgs e) in
> c:\inetpub\wwwroot\WebApplication1\WebForm1.aspx.v b:46
> System.Web.UI.Control.OnLoad(EventArgs e)
> System.Web.UI.Control.LoadRecursive()
> System.Web.UI.Page.ProcessRequestMain()
>
> I have tried to following to fix the problem.
> 1) Tried to add the asp.net user to sql server
> 2) Removed tcp/ip from the connect types to sql server
> 3) added a new user which i called "aspnetuser" to both computers then
> when
> into anonymous logins on IIS and added this user as the anonymous login
> user
> and unchecked the let IIS control the password and typed in the correct
> password.
> 4) change the asp.net user that the install of vs.net added and added them
> to the admin group on both machines. I have no problem login into sql
> server
> (windows authentication) when i use my local account i created on the xp
> workstation for me (im in the admin group).
> The only thing i have not used is impersonation and id rather not unless i
> have to. Course since i haven't tried it, i might have trouble with it
> too.
> Scratch what i just said above. I tried impersonaltion and it worked but
> id
> rather not use this if at all possible. I want to use the security that
> vs.net set up for the "asp.net" user. Is this possible without using
> impersonation?
> Thanks,
> Brent
Actually Rob, SQL Server does. I created two identical user accounts on both
the xp box and the windows 2003 box and used the same password. I can log
into query analyzer just fine using windows authentication. My sql server is
set up to use only windows authentication so username/password does not work
and i prefer to keep it this way. Also the server explorer works just fine
under the VS.Net IDE. I appreciate your reply though. Also when i create a
regular vb.net app; windows authentication works just fine.

Brent
"Rob Bazinet" <rbazinet66@.hotmail.com> wrote in message
news:OXR%23uFW0EHA.416@.TK2MSFTNGP10.phx.gbl...
> What does your connection string look like? If you are on a workgroup and
> NOT in a domain your sql server is not going to know the requesting user.
> Have you tried not using a trusted connection and use something like this
in
> your connection string:
> Server=(local);Initial Catalog=pubs;User Id=sa;Password=
> -Rob
> "Brent Waldrop" <brentwa@.spam.hotmail.com> wrote in message
> news:uUMCZ1V0EHA.3236@.TK2MSFTNGP15.phx.gbl...
> > Ok everyone, i have been pulling my hair out on this one. I have been
> > working on it for 3 days with no sucess. This problem is occuring at
home
> > where i am running a workgroup. I have Windows 2003 Ent Server on one
> > machine and windows xp sp2 on another. The db server is located on the
> > Windows 2003 machine. I am working locally with asp.net 1.1 on the xp
> > workstation and the web server is also locally on the xp workstation.
> > Every
> > time i try to connect with the asp.net application to the database i get
> > the
> > following error:
> > Server Error in '/WebApplication1' Application.
> -----------------------
--
> > --
> > Login failed for user '(null)'. Reason: Not associated with a trusted
SQL
> > Server connection.
> > Description: An unhandled exception occurred during the execution of the
> > current web request. Please review the stack trace for more information
> > about the error and where it originated in the code.
> > Exception Details: System.Data.SqlClient.SqlException: Login failed for
> > user
> > '(null)'. Reason: Not associated with a trusted SQL Server connection.
> > Source Error:
> > Line 44:
> > Line 45: ' fill the dataset
> > Line 46: dataAdapter.Fill(ds, "Customers")
> > Line 47: Dim bldr As New SqlCommandBuilder(dataAdapter)
> > Line 48:
> > Source File: c:\inetpub\wwwroot\WebApplication1\WebForm1.aspx.v b
Line:
> > 46
> > Stack Trace:
> > [SqlException: Login failed for user '(null)'. Reason: Not associated
with
> > a
> > trusted SQL Server connection.]
> > System.Data.SqlClient.ConnectionPool.GetConnection (Boolean&
> > isInTransaction)
System.Data.SqlClient.SqlConnectionPoolManager.Get PooledConnection(SqlConnec
> > tionString options, Boolean& isInTransaction)
> > System.Data.SqlClient.SqlConnection.Open()
> > System.Data.Common.DbDataAdapter.QuietOpen(IDbConn ection connection,
> > ConnectionState& originalState)
> > System.Data.Common.DbDataAdapter.FillFromCommand(O bject data, Int32
> > startRecord, Int32 maxRecords, String srcTable, IDbCommand command,
> > CommandBehavior behavior)
> > System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32
> > startRecord,
> > Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior
> > behavior)
> > System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String
srcTable)
> > WebApplication1.WebForm1.Page_Load(Object sender, EventArgs e) in
> > c:\inetpub\wwwroot\WebApplication1\WebForm1.aspx.v b:46
> > System.Web.UI.Control.OnLoad(EventArgs e)
> > System.Web.UI.Control.LoadRecursive()
> > System.Web.UI.Page.ProcessRequestMain()
> > I have tried to following to fix the problem.
> > 1) Tried to add the asp.net user to sql server
> > 2) Removed tcp/ip from the connect types to sql server
> > 3) added a new user which i called "aspnetuser" to both computers then
> > when
> > into anonymous logins on IIS and added this user as the anonymous login
> > user
> > and unchecked the let IIS control the password and typed in the correct
> > password.
> > 4) change the asp.net user that the install of vs.net added and added
them
> > to the admin group on both machines. I have no problem login into sql
> > server
> > (windows authentication) when i use my local account i created on the xp
> > workstation for me (im in the admin group).
> > The only thing i have not used is impersonation and id rather not unless
i
> > have to. Course since i haven't tried it, i might have trouble with it
> > too.
> > Scratch what i just said above. I tried impersonaltion and it worked but
> > id
> > rather not use this if at all possible. I want to use the security that
> > vs.net set up for the "asp.net" user. Is this possible without using
> > impersonation?
> > Thanks,
> > Brent
In this case, you need to add the IIS_WPG account to your database users.

"Brent Waldrop" <brentwa@.spam.hotmail.com> wrote in message
news:eDG6JRW0EHA.2976@.TK2MSFTNGP12.phx.gbl...
> Actually Rob, SQL Server does. I created two identical user accounts on both
> the xp box and the windows 2003 box and used the same password. I can log
> into query analyzer just fine using windows authentication. My sql server is
> set up to use only windows authentication so username/password does not work
> and i prefer to keep it this way. Also the server explorer works just fine
> under the VS.Net IDE. I appreciate your reply though. Also when i create a
> regular vb.net app; windows authentication works just fine.
> Brent
> "Rob Bazinet" <rbazinet66@.hotmail.com> wrote in message
> news:OXR%23uFW0EHA.416@.TK2MSFTNGP10.phx.gbl...
> > What does your connection string look like? If you are on a workgroup and
> > NOT in a domain your sql server is not going to know the requesting user.
> > Have you tried not using a trusted connection and use something like this
> in
> > your connection string:
> > Server=(local);Initial Catalog=pubs;User Id=sa;Password=
> > -Rob
> > "Brent Waldrop" <brentwa@.spam.hotmail.com> wrote in message
> > news:uUMCZ1V0EHA.3236@.TK2MSFTNGP15.phx.gbl...
> > > Ok everyone, i have been pulling my hair out on this one. I have been
> > > working on it for 3 days with no sucess. This problem is occuring at
> home
> > > where i am running a workgroup. I have Windows 2003 Ent Server on one
> > > machine and windows xp sp2 on another. The db server is located on the
> > > Windows 2003 machine. I am working locally with asp.net 1.1 on the xp
> > > workstation and the web server is also locally on the xp workstation.
> > > Every
> > > time i try to connect with the asp.net application to the database i get
> > > the
> > > following error:
> > > > Server Error in '/WebApplication1' Application.
> > -----------------------
> --
> > > --
> > > > Login failed for user '(null)'. Reason: Not associated with a trusted
> SQL
> > > Server connection.
> > > Description: An unhandled exception occurred during the execution of the
> > > current web request. Please review the stack trace for more information
> > > about the error and where it originated in the code.
> > > > Exception Details: System.Data.SqlClient.SqlException: Login failed for
> > > user
> > > '(null)'. Reason: Not associated with a trusted SQL Server connection.
> > > > Source Error:
> > > > > Line 44:
> > > Line 45: ' fill the dataset
> > > Line 46: dataAdapter.Fill(ds, "Customers")
> > > Line 47: Dim bldr As New SqlCommandBuilder(dataAdapter)
> > > Line 48:
> > > > > Source File: c:\inetpub\wwwroot\WebApplication1\WebForm1.aspx.v b
> Line:
> > > 46
> > > > Stack Trace:
> > > > > [SqlException: Login failed for user '(null)'. Reason: Not associated
> with
> > > a
> > > trusted SQL Server connection.]
> > > System.Data.SqlClient.ConnectionPool.GetConnection (Boolean&
> > > isInTransaction)
> > > System.Data.SqlClient.SqlConnectionPoolManager.Get PooledConnection(SqlConnec
> > > tionString options, Boolean& isInTransaction)
> > > System.Data.SqlClient.SqlConnection.Open()
> > > System.Data.Common.DbDataAdapter.QuietOpen(IDbConn ection connection,
> > > ConnectionState& originalState)
> > > System.Data.Common.DbDataAdapter.FillFromCommand(O bject data, Int32
> > > startRecord, Int32 maxRecords, String srcTable, IDbCommand command,
> > > CommandBehavior behavior)
> > > System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32
> > > startRecord,
> > > Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior
> > > behavior)
> > > System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String
> srcTable)
> > > WebApplication1.WebForm1.Page_Load(Object sender, EventArgs e) in
> > > c:\inetpub\wwwroot\WebApplication1\WebForm1.aspx.v b:46
> > > System.Web.UI.Control.OnLoad(EventArgs e)
> > > System.Web.UI.Control.LoadRecursive()
> > > System.Web.UI.Page.ProcessRequestMain()
> > > > > I have tried to following to fix the problem.
> > > > 1) Tried to add the asp.net user to sql server
> > > > 2) Removed tcp/ip from the connect types to sql server
> > > > 3) added a new user which i called "aspnetuser" to both computers then
> > > when
> > > into anonymous logins on IIS and added this user as the anonymous login
> > > user
> > > and unchecked the let IIS control the password and typed in the correct
> > > password.
> > > > 4) change the asp.net user that the install of vs.net added and added
> them
> > > to the admin group on both machines. I have no problem login into sql
> > > server
> > > (windows authentication) when i use my local account i created on the xp
> > > workstation for me (im in the admin group).
> > > > The only thing i have not used is impersonation and id rather not unless
> i
> > > have to. Course since i haven't tried it, i might have trouble with it
> > > too.
> > > > Scratch what i just said above. I tried impersonaltion and it worked but
> > > id
> > > rather not use this if at all possible. I want to use the security that
> > > vs.net set up for the "asp.net" user. Is this possible without using
> > > impersonation?
> > > > Thanks,
> > > Brent
> >
Just tried that...that doesn't work either.

"EC" <ec@.notmyrealaddress.com> wrote in message
news:OqqHtuX0EHA.3244@.TK2MSFTNGP10.phx.gbl...
> In this case, you need to add the IIS_WPG account to your database users.
> "Brent Waldrop" <brentwa@.spam.hotmail.com> wrote in message
> news:eDG6JRW0EHA.2976@.TK2MSFTNGP12.phx.gbl...
>> Actually Rob, SQL Server does. I created two identical user accounts on
>> both
>> the xp box and the windows 2003 box and used the same password. I can log
>> into query analyzer just fine using windows authentication. My sql server
>> is
>> set up to use only windows authentication so username/password does not
>> work
>> and i prefer to keep it this way. Also the server explorer works just
>> fine
>> under the VS.Net IDE. I appreciate your reply though. Also when i create
>> a
>> regular vb.net app; windows authentication works just fine.
>>
>> Brent
>> "Rob Bazinet" <rbazinet66@.hotmail.com> wrote in message
>> news:OXR%23uFW0EHA.416@.TK2MSFTNGP10.phx.gbl...
>> > What does your connection string look like? If you are on a workgroup
>> > and
>> > NOT in a domain your sql server is not going to know the requesting
>> > user.
>>> > Have you tried not using a trusted connection and use something like
>> > this
>> in
>> > your connection string:
>>> > Server=(local);Initial Catalog=pubs;User Id=sa;Password=
>>> > -Rob
>>> > "Brent Waldrop" <brentwa@.spam.hotmail.com> wrote in message
>> > news:uUMCZ1V0EHA.3236@.TK2MSFTNGP15.phx.gbl...
>> > > Ok everyone, i have been pulling my hair out on this one. I have been
>> > > working on it for 3 days with no sucess. This problem is occuring at
>> home
>> > > where i am running a workgroup. I have Windows 2003 Ent Server on
>> > > one
>> > > machine and windows xp sp2 on another. The db server is located on
>> > > the
>> > > Windows 2003 machine. I am working locally with asp.net 1.1 on the xp
>> > > workstation and the web server is also locally on the xp workstation.
>> > > Every
>> > > time i try to connect with the asp.net application to the database i
>> > > get
>> > > the
>> > > following error:
>> >> > > Server Error in '/WebApplication1' Application.
>>> > -----------------------
>> --
>> > > --
>> >> > > Login failed for user '(null)'. Reason: Not associated with a trusted
>> SQL
>> > > Server connection.
>> > > Description: An unhandled exception occurred during the execution of
>> > > the
>> > > current web request. Please review the stack trace for more
>> > > information
>> > > about the error and where it originated in the code.
>> >> > > Exception Details: System.Data.SqlClient.SqlException: Login failed
>> > > for
>> > > user
>> > > '(null)'. Reason: Not associated with a trusted SQL Server
>> > > connection.
>> >> > > Source Error:
>> >> >> > > Line 44:
>> > > Line 45: ' fill the dataset
>> > > Line 46: dataAdapter.Fill(ds, "Customers")
>> > > Line 47: Dim bldr As New SqlCommandBuilder(dataAdapter)
>> > > Line 48:
>> >> >> > > Source File: c:\inetpub\wwwroot\WebApplication1\WebForm1.aspx.v b
>> Line:
>> > > 46
>> >> > > Stack Trace:
>> >> >> > > [SqlException: Login failed for user '(null)'. Reason: Not associated
>> with
>> > > a
>> > > trusted SQL Server connection.]
>> > > System.Data.SqlClient.ConnectionPool.GetConnection (Boolean&
>> > > isInTransaction)
>> >> >> System.Data.SqlClient.SqlConnectionPoolManager.Get PooledConnection(SqlConnec
>> > > tionString options, Boolean& isInTransaction)
>> > > System.Data.SqlClient.SqlConnection.Open()
>> > > System.Data.Common.DbDataAdapter.QuietOpen(IDbConn ection
>> > > connection,
>> > > ConnectionState& originalState)
>> > > System.Data.Common.DbDataAdapter.FillFromCommand(O bject data, Int32
>> > > startRecord, Int32 maxRecords, String srcTable, IDbCommand command,
>> > > CommandBehavior behavior)
>> > > System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32
>> > > startRecord,
>> > > Int32 maxRecords, String srcTable, IDbCommand command,
>> > > CommandBehavior
>> > > behavior)
>> > > System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String
>> srcTable)
>> > > WebApplication1.WebForm1.Page_Load(Object sender, EventArgs e) in
>> > > c:\inetpub\wwwroot\WebApplication1\WebForm1.aspx.v b:46
>> > > System.Web.UI.Control.OnLoad(EventArgs e)
>> > > System.Web.UI.Control.LoadRecursive()
>> > > System.Web.UI.Page.ProcessRequestMain()
>> >> >> > > I have tried to following to fix the problem.
>> >> > > 1) Tried to add the asp.net user to sql server
>> >> > > 2) Removed tcp/ip from the connect types to sql server
>> >> > > 3) added a new user which i called "aspnetuser" to both computers
>> > > then
>> > > when
>> > > into anonymous logins on IIS and added this user as the anonymous
>> > > login
>> > > user
>> > > and unchecked the let IIS control the password and typed in the
>> > > correct
>> > > password.
>> >> > > 4) change the asp.net user that the install of vs.net added and added
>> them
>> > > to the admin group on both machines. I have no problem login into sql
>> > > server
>> > > (windows authentication) when i use my local account i created on the
>> > > xp
>> > > workstation for me (im in the admin group).
>> >> > > The only thing i have not used is impersonation and id rather not
>> > > unless
>> i
>> > > have to. Course since i haven't tried it, i might have trouble with
>> > > it
>> > > too.
>> >> > > Scratch what i just said above. I tried impersonaltion and it worked
>> > > but
>> > > id
>> > > rather not use this if at all possible. I want to use the security
>> > > that
>> > > vs.net set up for the "asp.net" user. Is this possible without using
>> > > impersonation?
>> >> > > Thanks,
>> > > Brent
>> >> >>>>
>>

Wednesday, March 28, 2012

Trouble accessing .NET 2.0 Membership stuff from HTTP Module

I am trying to create an HTTP module to run on ASP.NET 2.0. The module needs
to check to see if the user is authenticated with the .net 2.0 membership
stuff. I am trying this:

If application.Context.User.Identity.IsAuthenticated Then
app.Context.Response.Write("user authenticated")
End If

I get a "Object Reference not set to an instance of anobject." error on
application.Context.User.Identity.IsAuthenticated.

I am always getting an error. Does anyone have any suggestions? Do I need
to configure anything special for the module? Thanks.You should look into handling the PostAuthenticateRequest event instead.
That way you don't have ordering issues with the other modules during the
AuthenticateRequest event.

-Brock
DevelopMentor
http://staff.develop.com/ballen

> I am trying to create an HTTP module to run on ASP.NET 2.0. The
> module needs to check to see if the user is authenticated with the
> .net 2.0 membership stuff. I am trying this:
> If application.Context.User.Identity.IsAuthenticated Then
> app.Context.Response.Write("user authenticated")
> End If
> I get a "Object Reference not set to an instance of anobject." error
> on application.Context.User.Identity.IsAuthenticated.
> I am always getting an error. Does anyone have any suggestions? Do I
> need to configure anything special for the module? Thanks.
Thanks. That fixed it.

"Brock Allen" wrote:

> You should look into handling the PostAuthenticateRequest event instead.
> That way you don't have ordering issues with the other modules during the
> AuthenticateRequest event.
> -Brock
> DevelopMentor
> http://staff.develop.com/ballen
>
> > I am trying to create an HTTP module to run on ASP.NET 2.0. The
> > module needs to check to see if the user is authenticated with the
> > .net 2.0 membership stuff. I am trying this:
> > If application.Context.User.Identity.IsAuthenticated Then
> > app.Context.Response.Write("user authenticated")
> > End If
> > I get a "Object Reference not set to an instance of anobject." error
> > on application.Context.User.Identity.IsAuthenticated.
> > I am always getting an error. Does anyone have any suggestions? Do I
> > need to configure anything special for the module? Thanks.
>
>

Trouble accesing IIS 5.1

Hiya,

I am trying to open a new ASP.NET Web Application Project using Visual Studio .NET, but it is denied with the following error:

Web Server reported the following error when attempting to create or open the Web Project located at the following URL : "http://localhost/WebApplication1"
'HTTP/1.1 403 Access Forbidden'

I installed everything correctly, first IIS 5.1, then Visual Studio .NET with the update of ASP.NET to 1.1. The error was there even before the update, so I don't think that might be a cause for this problem.

Would appreciate your help guys, as I have to submit the project soon, and really need to get going. Thanks ever so much.To fix IIS mappings for ASP.NET, follow these steps:

1. Click Start -> run -> cmd - ENTER
2. At the command prompt, type the following, and then press ENTER:
"%windir%\Microsoft.NET\Framework\version\aspnet_regiis.exe" -i

In this path, version represents the version number of the .NET Framework that you installed on your server. You need to replace with the actual version number when you type the command.

3. Register the Aspnet_isapi.dll by clicking start -> run
4. In the Open text box, type "regsvr32 %windir%\Microsoft.NET\Framework\version\aspnet_isapi.dll" and then press ENTER
I have re-installed everything, first IIS 5.1, then Visual Studio .NET. Now, it is coming up with the "HTTP/1.1 500 Sever Error"

My initial problem was solved when I followed advice posted below:

http://weblogs.asp.net/jblizzard/archive/2003/07/28/10623.aspx

When I tried to run commands you provided, it returned an error, saying The command is not specified. I suspect it might be because I put 1.1 instead of version in that command. Probably it is not just 1.1 but the full version, which I don't know. Could you advice.

Thanks once again for your kind help.

Troubble with links in emails

I'm having trouble with links in emails which are sent from my webapp. I'm using System.Net.Mail.SmtpClient and sending mails as plain text. My email body contains a link e.g.http://www.blabla.com/Page.aspx. Some times the dot between blabla and com disappears when the recipient gets the mail.
I was sure this was an issue with the mail client, but apparently many of our customers are experiencing the same problem. I haven't been able to reproduce this problem myself because all my email clients display the links properly, but I have had some of our clients forward the mails to me, and the dot is actually missing. (http://www.blablacom/Page.aspx).
Have any of you guys seen this problem before? And how can I solve it?Are you still using the Beta version??
Yes, this is beta 2. I haven't been able to test it on the final version yet, because I can't reproduce the problem myself and we haven't shipped the new version to our customers yet.
Do you think it will work differently in the final version?
This is an issue that I haven't heard of earlier. I suggest you download the RTM of the .Net Framework and install it (remember to uninstall any beta version before installing if you intend to do this on the same machine). If your problem remains, I suggest you check the original data and code for string manipulation methods which may cause dots to disappear.
We uninstalled Beta 2 and installed RTM. This solved the problem without any changes to the code.

Trouble Accessing Data File from .Net App

I am having trouble accessing a datafile in my inetpub/wwwroot/_private
directory from a VB .Net app that I am debugging. When I run the program I
get an error saying that ASPNET is not authorized to use the file. When I
right-click the file in question and select the Security tab ASPNET is not
listed under User Names ... but Internet Guest Account and Launch IIS
Process Account are listed [along with a couple of others]. I am running
iis 5.1 and have installed .Net Framework Version 1.1 Redistirbutable
Package.
Thanks.

Try to add the ASPNET acocunt to that folder.
Regards

Trouble accessing object before insertion into panel...

Hey everyone,

I have a script that presents the user with a variable number of text boxes (with the ID's "TextBox1", "TextBox2", "TextBox3", etc.) with an image button, and a label asking the user for input. All this is contained in a panel called Panel1. The user puts some text into the boxes and clicks the image button.

When clicked, the image button raises an event that tries and access the text the user entered in the text boxes, assign that text to a label, and display it in Panel2. It will then hide Panel1 and make Panel2 visible. The event generates an error however. I don't understand the error because the code seems straight forward. Here is the code (intTxtCount contains the number of text boxes that the user was presented with):


Public Sub cmdContinueToDeparturePoints(Sender As Object, e As System.Web.UI.ImageClickEventArgs)

Dim i As Integer
For i = 1 To intTxtCount
Dim lblName As New Label()
lblName.ID = "lblName" & i
Dim txtTemp As TextBox
txtTemp = FindControl("TextBox" & i)
lblName.Text = txtTemp.Text '''' Error Generating Line
Panel2.Controls.Add(lblName)
Panel2.Controls.Add(New LiteralControl("<br>"))
Next i

Panel1.Visible = False
Panel2.Visible = True

End Sub


Here is the Error:

System.NullReferenceException: Object reference not set to an instance of an object.

I think this error is telling me that a control called lblName does not exist physically in my panel, which is true. But if I reference lblName the object (the one I just declared in the sub) shouldn't that be okay? Am I wrong?

Bewildering...Mike :-/1. NullReferenceException is one of the most common programming errors. So it will help to really learn it well. It means that an object that is being dereferenced (the object followed by a period) is 'null' or 'nothing' in VB terms.

In this line, there are two objects being dereferenced:
lblName.Text = txtTemp.Text

lblName is created just above and you dereferenced it when you assigned the ID. So that's not it. txtTemp is the result of FindControl. You are assuming that you will find a control with the ID "TextBox1" (or whatever number 'i' is when this fails). It is returning null at some point.

2. Its likely that you have not recreated the same list of TextBoxes on post back before this loop executes. Also consider that you have a loop maximum in variable that may not reflect the true number of textboxes.

3. If you are going to write code, please consider using a debugger. Single-step through code and review the values of variables, parameters, and properties as things happen. The debugger would stop on the line with the error and let you open a Watch or Local Variable window to see what the values are in lblName and txtTemp.
Peter,

Thanks for such a great response. Yes, I should be using a debugger. If only my company were not so cheap as to let me code without VisualStudio.NET... :-(

Ok. So we have managed to conclude that lblName is not generating the Null Exception. It must be that no value is being assigned to txtTemp.Text from "TextBox1". Your comments in line item number 2 really interest me:

What do you mean by, "you have not recreated the same list of TextBoxes on post back before this loop executes"? I have never had to "recreate" a form for a PostBack event. I don't even know what you mean by that. And as for the maximum loop variable, I am positive this value is correct every time the script runs. The HTML that the server generages clearly shows me the correct number of text boxes, all with the correct names (TextBox1, T...2, T...3, etc.). I don't understand why when this form is submitted and I try to assign the boxes values they are null. Just don't get it.

Here is some code that works fine, this is what I based my current work on:


Sub Page_Load(sender As Object, e As EventArgs)

Dim t As New TextBox()
Dim i As Integer = 1
t.Text = "testtext" & i.ToString()
t.ID = "myTextBox" & i.ToString()
Panel1.Controls.Add(t)
ViewState("i") = i

End Sub

Sub GetTextBoxValueAndAssignToLabel(sender As Object, e As System.EventArgs)

Dim i As Integer
i = ViewState("i")
Dim txtTemp As TextBox
txtTemp = FindControl("myTextBox" & i)
lblTest.Text = txtTemp.Text

End Sub


As you can see, a text box is created that has an ID of "myTextBox1". The number i is passed via ViewState to the event code for the button, and the Text property of the text box is successfully assigned to the label. As far as I can see, the only difference between my code and the code here is that the label control already exists in the form instead of the on-the-fly label creation I used.
Let's start with that darn debugger issue. My sympathies about your situation. The time you waste without a debugger will easily exceed the cost of VS.NET.

In the meantime, did you know that .net framework comes with a debugger? Lookup "DbgClr.exe" at MSDN.Microsoft.com. I have not used it though, since I'm using VS.NET.

On to your code. I'm confused by this, perhaps because you simplified it. I though you had a loop going on. I'm interested in that loop. For example, if you are assigning ViewState("i") = i in each interation of the loop, you are not changing the key passed to ViewState, and thus overwriting the value.

Please do this too: set <@.Page Trace=true >. When the page is first generated, it will show you each control by its ID. FindControl will only search in the "naming container" of that method. In this case, whatever object contains GetTextBoxValueAndAssignToLabel() is the naming container you are searching. If you did Panel1.FindControl, you will be assured of getting values from Panel1. Another thing you can do is simply grab each unique item in Panel1.Controls.
Panel1.Controls(0) - contains TextBox1
Panel1.Controls(1) - contains TextBox2

Trouble authenticating to Remote SQL Server

Ok everyone, i have been pulling my hair out on this one. I have been
working on it for 3 days with no sucess. This problem is occuring at home
where i am running a workgroup. I have Windows 2003 Ent Server on one
machine and Windows XP sp2 on another. The db server is located on the
Windows 2003 machine. I am working locally with asp.net 1.1 on the xp
workstation and the web server is also locally on the xp workstation. Every
time i try to connect with the asp.net application to the database i get the
following error:
Server Error in '/WebApplication1' Application.
----
--
Login failed for user '(null)'. Reason: Not associated with a trusted SQL
Server connection.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Login failed for user
'(null)'. Reason: Not associated with a trusted SQL Server connection.
Source Error:
Line 44:
Line 45: ' fill the dataset
Line 46: dataAdapter.Fill(ds, "Customers")
Line 47: Dim bldr As New SqlCommandBuilder(dataAdapter)
Line 48:
Source File: c:\inetpub\wwwroot\WebApplication1\WebFo
rm1.aspx.vb Line: 46
Stack Trace:
[SqlException: Login failed for user '(null)'. Reason: Not associated with a
trusted SQL Server connection.]
System.Data.SqlClient.ConnectionPool.GetConnection(Boolean&
isInTransaction)
System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnec
tionString options, Boolean& isInTransaction)
System.Data.SqlClient.SqlConnection.Open()
System.Data.Common.DbDataAdapter.QuietOpen(IDbConnection connection,
ConnectionState& originalState)
System.Data.Common.DbDataAdapter.FillFromCommand(Object data, Int32
startRecord, Int32 maxRecords, String srcTable, IDbCommand command,
CommandBehavior behavior)
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord,
Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior
behavior)
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable)
WebApplication1.WebForm1.Page_Load(Object sender, EventArgs e) in
c:\inetpub\wwwroot\WebApplication1\WebFo
rm1.aspx.vb:46
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()
I have tried to following to fix the problem.
1) Tried to add the asp.net user to sql server
2) Removed tcp/ip from the connect types to sql server
3) added a new user which i called "aspnetuser" to both computers then when
into anonymous logins on IIS and added this user as the anonymous login user
and unchecked the let IIS control the password and typed in the correct
password.
4) change the asp.net user that the install of vs.net added and added them
to the admin group on both machines. I have no problem login into sql server
(windows authentication) when i use my local account i created on the xp
workstation for me (im in the admin group).
The only thing i have not used is impersonation and id rather not unless i
have to. Course since i haven't tried it, i might have trouble with it too.
Scratch what i just said above. I tried impersonaltion and it worked but id
rather not use this if at all possible. I want to use the security that
vs.net set up for the "asp.net" user. Is this possible without using
impersonation?
Thanks,
BrentWhat does your connection string look like? If you are on a workgroup and
NOT in a domain your sql server is not going to know the requesting user.
Have you tried not using a trusted connection and use something like this in
your connection string:
Server=(local);Initial Catalog=pubs;User Id=sa;Password=
-Rob
"Brent Waldrop" <brentwa@.spam.hotmail.com> wrote in message
news:uUMCZ1V0EHA.3236@.TK2MSFTNGP15.phx.gbl...
> Ok everyone, i have been pulling my hair out on this one. I have been
> working on it for 3 days with no sucess. This problem is occuring at home
> where i am running a workgroup. I have Windows 2003 Ent Server on one
> machine and Windows XP sp2 on another. The db server is located on the
> Windows 2003 machine. I am working locally with asp.net 1.1 on the xp
> workstation and the web server is also locally on the xp workstation.
> Every
> time i try to connect with the asp.net application to the database i get
> the
> following error:
> Server Error in '/WebApplication1' Application.
> ----
--
> --
> Login failed for user '(null)'. Reason: Not associated with a trusted SQL
> Server connection.
> Description: An unhandled exception occurred during the execution of the
> current web request. Please review the stack trace for more information
> about the error and where it originated in the code.
> Exception Details: System.Data.SqlClient.SqlException: Login failed for
> user
> '(null)'. Reason: Not associated with a trusted SQL Server connection.
> Source Error:
>
> Line 44:
> Line 45: ' fill the dataset
> Line 46: dataAdapter.Fill(ds, "Customers")
> Line 47: Dim bldr As New SqlCommandBuilder(dataAdapter)
> Line 48:
>
> Source File: c:\inetpub\wwwroot\WebApplication1\WebFo
rm1.aspx.vb Line:
> 46
> Stack Trace:
>
> [SqlException: Login failed for user '(null)'. Reason: Not associated with
> a
> trusted SQL Server connection.]
> System.Data.SqlClient.ConnectionPool.GetConnection(Boolean&
> isInTransaction)
> System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConn
ec
> tionString options, Boolean& isInTransaction)
> System.Data.SqlClient.SqlConnection.Open()
> System.Data.Common.DbDataAdapter.QuietOpen(IDbConnection connection,
> ConnectionState& originalState)
> System.Data.Common.DbDataAdapter.FillFromCommand(Object data, Int32
> startRecord, Int32 maxRecords, String srcTable, IDbCommand command,
> CommandBehavior behavior)
> System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32
> startRecord,
> Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior
> behavior)
> System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable)
> WebApplication1.WebForm1.Page_Load(Object sender, EventArgs e) in
> c:\inetpub\wwwroot\WebApplication1\WebFo
rm1.aspx.vb:46
> System.Web.UI.Control.OnLoad(EventArgs e)
> System.Web.UI.Control.LoadRecursive()
> System.Web.UI.Page.ProcessRequestMain()
>
> I have tried to following to fix the problem.
> 1) Tried to add the asp.net user to sql server
> 2) Removed tcp/ip from the connect types to sql server
> 3) added a new user which i called "aspnetuser" to both computers then
> when
> into anonymous logins on IIS and added this user as the anonymous login
> user
> and unchecked the let IIS control the password and typed in the correct
> password.
> 4) change the asp.net user that the install of vs.net added and added them
> to the admin group on both machines. I have no problem login into sql
> server
> (windows authentication) when i use my local account i created on the xp
> workstation for me (im in the admin group).
> The only thing i have not used is impersonation and id rather not unless i
> have to. Course since i haven't tried it, i might have trouble with it
> too.
> Scratch what i just said above. I tried impersonaltion and it worked but
> id
> rather not use this if at all possible. I want to use the security that
> vs.net set up for the "asp.net" user. Is this possible without using
> impersonation?
> Thanks,
> Brent
>
Actually Rob, SQL Server does. I created two identical user accounts on both
the xp box and the windows 2003 box and used the same password. I can log
into query analyzer just fine using windows authentication. My sql server is
set up to use only windows authentication so username/password does not work
and i prefer to keep it this way. Also the server explorer works just fine
under the VS.Net IDE. I appreciate your reply though. Also when i create a
regular vb.net app; windows authentication works just fine.
Brent
"Rob Bazinet" <rbazinet66@.hotmail.com> wrote in message
news:OXR%23uFW0EHA.416@.TK2MSFTNGP10.phx.gbl...
> What does your connection string look like? If you are on a workgroup and
> NOT in a domain your sql server is not going to know the requesting user.
> Have you tried not using a trusted connection and use something like this
in
> your connection string:
> Server=(local);Initial Catalog=pubs;User Id=sa;Password=
> -Rob
> "Brent Waldrop" <brentwa@.spam.hotmail.com> wrote in message
> news:uUMCZ1V0EHA.3236@.TK2MSFTNGP15.phx.gbl...
home
> ----
--
SQL
Line:
with
System.Data.SqlClient.SqlConnectionPoolManager. GetPooledConnection(SqlConnec[color=dark
red]
srcTable)
them
i
>
In this case, you need to add the IIS_WPG account to your database users.
"Brent Waldrop" <brentwa@.spam.hotmail.com> wrote in message
news:eDG6JRW0EHA.2976@.TK2MSFTNGP12.phx.gbl...
> Actually Rob, SQL Server does. I created two identical user accounts on bo
th
> the xp box and the windows 2003 box and used the same password. I can log
> into query analyzer just fine using windows authentication. My sql server
is
> set up to use only windows authentication so username/password does not wo
rk
> and i prefer to keep it this way. Also the server explorer works just fine
> under the VS.Net IDE. I appreciate your reply though. Also when i create a
> regular vb.net app; windows authentication works just fine.
> Brent
> "Rob Bazinet" <rbazinet66@.hotmail.com> wrote in message
> news:OXR%23uFW0EHA.416@.TK2MSFTNGP10.phx.gbl...
> in
> home
> --
> SQL
> Line:
> with
> System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConn
ec
> srcTable)
> them
> i
>
Just tried that...that doesn't work either.
"EC" <ec@.notmyrealaddress.com> wrote in message
news:OqqHtuX0EHA.3244@.TK2MSFTNGP10.phx.gbl...
> In this case, you need to add the IIS_WPG account to your database users.
> "Brent Waldrop" <brentwa@.spam.hotmail.com> wrote in message
> news:eDG6JRW0EHA.2976@.TK2MSFTNGP12.phx.gbl...
>

Trouble authenticating to Remote SQL Server

Ok everyone, i have been pulling my hair out on this one. I have been
working on it for 3 days with no sucess. This problem is occuring at home
where i am running a workgroup. I have Windows 2003 Ent Server on one
machine and windows xp sp2 on another. The db server is located on the
Windows 2003 machine. I am working locally with asp.net 1.1 on the xp
workstation and the web server is also locally on the xp workstation. Every
time i try to connect with the asp.net application to the database i get the
following error:

Server Error in '/WebApplication1' Application.
-----------------------
--

Login failed for user '(null)'. Reason: Not associated with a trusted SQL
Server connection.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Login failed for user
'(null)'. Reason: Not associated with a trusted SQL Server connection.

Source Error:

Line 44:
Line 45: ' fill the dataset
Line 46: dataAdapter.Fill(ds, "Customers")
Line 47: Dim bldr As New SqlCommandBuilder(dataAdapter)
Line 48:

Source File: c:\inetpub\wwwroot\WebApplication1\WebForm1.aspx.v b Line: 46

Stack Trace:

[SqlException: Login failed for user '(null)'. Reason: Not associated with a
trusted SQL Server connection.]
System.Data.SqlClient.ConnectionPool.GetConnection (Boolean&
isInTransaction)

System.Data.SqlClient.SqlConnectionPoolManager.Get PooledConnection(SqlConnec
tionString options, Boolean& isInTransaction)
System.Data.SqlClient.SqlConnection.Open()
System.Data.Common.DbDataAdapter.QuietOpen(IDbConn ection connection,
ConnectionState& originalState)
System.Data.Common.DbDataAdapter.FillFromCommand(O bject data, Int32
startRecord, Int32 maxRecords, String srcTable, IDbCommand command,
CommandBehavior behavior)
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord,
Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior
behavior)
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable)
WebApplication1.WebForm1.Page_Load(Object sender, EventArgs e) in
c:\inetpub\wwwroot\WebApplication1\WebForm1.aspx.v b:46
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()

I have tried to following to fix the problem.

1) Tried to add the asp.net user to sql server

2) Removed tcp/ip from the connect types to sql server

3) added a new user which i called "aspnetuser" to both computers then when
into anonymous logins on IIS and added this user as the anonymous login user
and unchecked the let IIS control the password and typed in the correct
password.

4) change the asp.net user that the install of vs.net added and added them
to the admin group on both machines. I have no problem login into sql server
(windows authentication) when i use my local account i created on the xp
workstation for me (im in the admin group).

The only thing i have not used is impersonation and id rather not unless i
have to. Course since i haven't tried it, i might have trouble with it too.

Scratch what i just said above. I tried impersonaltion and it worked but id
rather not use this if at all possible. I want to use the security that
vs.net set up for the "asp.net" user. Is this possible without using
impersonation?

Thanks,
BrentWhat does your connection string look like? If you are on a workgroup and
NOT in a domain your sql server is not going to know the requesting user.

Have you tried not using a trusted connection and use something like this in
your connection string:

Server=(local);Initial Catalog=pubs;User Id=sa;Password=

-Rob

"Brent Waldrop" <brentwa@.spam.hotmail.com> wrote in message
news:uUMCZ1V0EHA.3236@.TK2MSFTNGP15.phx.gbl...
> Ok everyone, i have been pulling my hair out on this one. I have been
> working on it for 3 days with no sucess. This problem is occuring at home
> where i am running a workgroup. I have Windows 2003 Ent Server on one
> machine and windows xp sp2 on another. The db server is located on the
> Windows 2003 machine. I am working locally with asp.net 1.1 on the xp
> workstation and the web server is also locally on the xp workstation.
> Every
> time i try to connect with the asp.net application to the database i get
> the
> following error:
> Server Error in '/WebApplication1' Application.
> -----------------------
> --
> Login failed for user '(null)'. Reason: Not associated with a trusted SQL
> Server connection.
> Description: An unhandled exception occurred during the execution of the
> current web request. Please review the stack trace for more information
> about the error and where it originated in the code.
> Exception Details: System.Data.SqlClient.SqlException: Login failed for
> user
> '(null)'. Reason: Not associated with a trusted SQL Server connection.
> Source Error:
>
> Line 44:
> Line 45: ' fill the dataset
> Line 46: dataAdapter.Fill(ds, "Customers")
> Line 47: Dim bldr As New SqlCommandBuilder(dataAdapter)
> Line 48:
>
> Source File: c:\inetpub\wwwroot\WebApplication1\WebForm1.aspx.v b Line:
> 46
> Stack Trace:
>
> [SqlException: Login failed for user '(null)'. Reason: Not associated with
> a
> trusted SQL Server connection.]
> System.Data.SqlClient.ConnectionPool.GetConnection (Boolean&
> isInTransaction)
> System.Data.SqlClient.SqlConnectionPoolManager.Get PooledConnection(SqlConnec
> tionString options, Boolean& isInTransaction)
> System.Data.SqlClient.SqlConnection.Open()
> System.Data.Common.DbDataAdapter.QuietOpen(IDbConn ection connection,
> ConnectionState& originalState)
> System.Data.Common.DbDataAdapter.FillFromCommand(O bject data, Int32
> startRecord, Int32 maxRecords, String srcTable, IDbCommand command,
> CommandBehavior behavior)
> System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32
> startRecord,
> Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior
> behavior)
> System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable)
> WebApplication1.WebForm1.Page_Load(Object sender, EventArgs e) in
> c:\inetpub\wwwroot\WebApplication1\WebForm1.aspx.v b:46
> System.Web.UI.Control.OnLoad(EventArgs e)
> System.Web.UI.Control.LoadRecursive()
> System.Web.UI.Page.ProcessRequestMain()
>
> I have tried to following to fix the problem.
> 1) Tried to add the asp.net user to sql server
> 2) Removed tcp/ip from the connect types to sql server
> 3) added a new user which i called "aspnetuser" to both computers then
> when
> into anonymous logins on IIS and added this user as the anonymous login
> user
> and unchecked the let IIS control the password and typed in the correct
> password.
> 4) change the asp.net user that the install of vs.net added and added them
> to the admin group on both machines. I have no problem login into sql
> server
> (windows authentication) when i use my local account i created on the xp
> workstation for me (im in the admin group).
> The only thing i have not used is impersonation and id rather not unless i
> have to. Course since i haven't tried it, i might have trouble with it
> too.
> Scratch what i just said above. I tried impersonaltion and it worked but
> id
> rather not use this if at all possible. I want to use the security that
> vs.net set up for the "asp.net" user. Is this possible without using
> impersonation?
> Thanks,
> Brent
Actually Rob, SQL Server does. I created two identical user accounts on both
the xp box and the windows 2003 box and used the same password. I can log
into query analyzer just fine using windows authentication. My sql server is
set up to use only windows authentication so username/password does not work
and i prefer to keep it this way. Also the server explorer works just fine
under the VS.Net IDE. I appreciate your reply though. Also when i create a
regular vb.net app; windows authentication works just fine.

Brent
"Rob Bazinet" <rbazinet66@.hotmail.com> wrote in message
news:OXR%23uFW0EHA.416@.TK2MSFTNGP10.phx.gbl...
> What does your connection string look like? If you are on a workgroup and
> NOT in a domain your sql server is not going to know the requesting user.
> Have you tried not using a trusted connection and use something like this
in
> your connection string:
> Server=(local);Initial Catalog=pubs;User Id=sa;Password=
> -Rob
> "Brent Waldrop" <brentwa@.spam.hotmail.com> wrote in message
> news:uUMCZ1V0EHA.3236@.TK2MSFTNGP15.phx.gbl...
> > Ok everyone, i have been pulling my hair out on this one. I have been
> > working on it for 3 days with no sucess. This problem is occuring at
home
> > where i am running a workgroup. I have Windows 2003 Ent Server on one
> > machine and windows xp sp2 on another. The db server is located on the
> > Windows 2003 machine. I am working locally with asp.net 1.1 on the xp
> > workstation and the web server is also locally on the xp workstation.
> > Every
> > time i try to connect with the asp.net application to the database i get
> > the
> > following error:
> > Server Error in '/WebApplication1' Application.
> -----------------------
--
> > --
> > Login failed for user '(null)'. Reason: Not associated with a trusted
SQL
> > Server connection.
> > Description: An unhandled exception occurred during the execution of the
> > current web request. Please review the stack trace for more information
> > about the error and where it originated in the code.
> > Exception Details: System.Data.SqlClient.SqlException: Login failed for
> > user
> > '(null)'. Reason: Not associated with a trusted SQL Server connection.
> > Source Error:
> > Line 44:
> > Line 45: ' fill the dataset
> > Line 46: dataAdapter.Fill(ds, "Customers")
> > Line 47: Dim bldr As New SqlCommandBuilder(dataAdapter)
> > Line 48:
> > Source File: c:\inetpub\wwwroot\WebApplication1\WebForm1.aspx.v b
Line:
> > 46
> > Stack Trace:
> > [SqlException: Login failed for user '(null)'. Reason: Not associated
with
> > a
> > trusted SQL Server connection.]
> > System.Data.SqlClient.ConnectionPool.GetConnection (Boolean&
> > isInTransaction)
System.Data.SqlClient.SqlConnectionPoolManager.Get PooledConnection(SqlConnec
> > tionString options, Boolean& isInTransaction)
> > System.Data.SqlClient.SqlConnection.Open()
> > System.Data.Common.DbDataAdapter.QuietOpen(IDbConn ection connection,
> > ConnectionState& originalState)
> > System.Data.Common.DbDataAdapter.FillFromCommand(O bject data, Int32
> > startRecord, Int32 maxRecords, String srcTable, IDbCommand command,
> > CommandBehavior behavior)
> > System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32
> > startRecord,
> > Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior
> > behavior)
> > System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String
srcTable)
> > WebApplication1.WebForm1.Page_Load(Object sender, EventArgs e) in
> > c:\inetpub\wwwroot\WebApplication1\WebForm1.aspx.v b:46
> > System.Web.UI.Control.OnLoad(EventArgs e)
> > System.Web.UI.Control.LoadRecursive()
> > System.Web.UI.Page.ProcessRequestMain()
> > I have tried to following to fix the problem.
> > 1) Tried to add the asp.net user to sql server
> > 2) Removed tcp/ip from the connect types to sql server
> > 3) added a new user which i called "aspnetuser" to both computers then
> > when
> > into anonymous logins on IIS and added this user as the anonymous login
> > user
> > and unchecked the let IIS control the password and typed in the correct
> > password.
> > 4) change the asp.net user that the install of vs.net added and added
them
> > to the admin group on both machines. I have no problem login into sql
> > server
> > (windows authentication) when i use my local account i created on the xp
> > workstation for me (im in the admin group).
> > The only thing i have not used is impersonation and id rather not unless
i
> > have to. Course since i haven't tried it, i might have trouble with it
> > too.
> > Scratch what i just said above. I tried impersonaltion and it worked but
> > id
> > rather not use this if at all possible. I want to use the security that
> > vs.net set up for the "asp.net" user. Is this possible without using
> > impersonation?
> > Thanks,
> > Brent
In this case, you need to add the IIS_WPG account to your database users.

"Brent Waldrop" <brentwa@.spam.hotmail.com> wrote in message
news:eDG6JRW0EHA.2976@.TK2MSFTNGP12.phx.gbl...
> Actually Rob, SQL Server does. I created two identical user accounts on both
> the xp box and the windows 2003 box and used the same password. I can log
> into query analyzer just fine using windows authentication. My sql server is
> set up to use only windows authentication so username/password does not work
> and i prefer to keep it this way. Also the server explorer works just fine
> under the VS.Net IDE. I appreciate your reply though. Also when i create a
> regular vb.net app; windows authentication works just fine.
> Brent
> "Rob Bazinet" <rbazinet66@.hotmail.com> wrote in message
> news:OXR%23uFW0EHA.416@.TK2MSFTNGP10.phx.gbl...
> > What does your connection string look like? If you are on a workgroup and
> > NOT in a domain your sql server is not going to know the requesting user.
> > Have you tried not using a trusted connection and use something like this
> in
> > your connection string:
> > Server=(local);Initial Catalog=pubs;User Id=sa;Password=
> > -Rob
> > "Brent Waldrop" <brentwa@.spam.hotmail.com> wrote in message
> > news:uUMCZ1V0EHA.3236@.TK2MSFTNGP15.phx.gbl...
> > > Ok everyone, i have been pulling my hair out on this one. I have been
> > > working on it for 3 days with no sucess. This problem is occuring at
> home
> > > where i am running a workgroup. I have Windows 2003 Ent Server on one
> > > machine and windows xp sp2 on another. The db server is located on the
> > > Windows 2003 machine. I am working locally with asp.net 1.1 on the xp
> > > workstation and the web server is also locally on the xp workstation.
> > > Every
> > > time i try to connect with the asp.net application to the database i get
> > > the
> > > following error:
> > > > Server Error in '/WebApplication1' Application.
> > -----------------------
> --
> > > --
> > > > Login failed for user '(null)'. Reason: Not associated with a trusted
> SQL
> > > Server connection.
> > > Description: An unhandled exception occurred during the execution of the
> > > current web request. Please review the stack trace for more information
> > > about the error and where it originated in the code.
> > > > Exception Details: System.Data.SqlClient.SqlException: Login failed for
> > > user
> > > '(null)'. Reason: Not associated with a trusted SQL Server connection.
> > > > Source Error:
> > > > > Line 44:
> > > Line 45: ' fill the dataset
> > > Line 46: dataAdapter.Fill(ds, "Customers")
> > > Line 47: Dim bldr As New SqlCommandBuilder(dataAdapter)
> > > Line 48:
> > > > > Source File: c:\inetpub\wwwroot\WebApplication1\WebForm1.aspx.v b
> Line:
> > > 46
> > > > Stack Trace:
> > > > > [SqlException: Login failed for user '(null)'. Reason: Not associated
> with
> > > a
> > > trusted SQL Server connection.]
> > > System.Data.SqlClient.ConnectionPool.GetConnection (Boolean&
> > > isInTransaction)
> > > System.Data.SqlClient.SqlConnectionPoolManager.Get PooledConnection(SqlConnec
> > > tionString options, Boolean& isInTransaction)
> > > System.Data.SqlClient.SqlConnection.Open()
> > > System.Data.Common.DbDataAdapter.QuietOpen(IDbConn ection connection,
> > > ConnectionState& originalState)
> > > System.Data.Common.DbDataAdapter.FillFromCommand(O bject data, Int32
> > > startRecord, Int32 maxRecords, String srcTable, IDbCommand command,
> > > CommandBehavior behavior)
> > > System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32
> > > startRecord,
> > > Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior
> > > behavior)
> > > System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String
> srcTable)
> > > WebApplication1.WebForm1.Page_Load(Object sender, EventArgs e) in
> > > c:\inetpub\wwwroot\WebApplication1\WebForm1.aspx.v b:46
> > > System.Web.UI.Control.OnLoad(EventArgs e)
> > > System.Web.UI.Control.LoadRecursive()
> > > System.Web.UI.Page.ProcessRequestMain()
> > > > > I have tried to following to fix the problem.
> > > > 1) Tried to add the asp.net user to sql server
> > > > 2) Removed tcp/ip from the connect types to sql server
> > > > 3) added a new user which i called "aspnetuser" to both computers then
> > > when
> > > into anonymous logins on IIS and added this user as the anonymous login
> > > user
> > > and unchecked the let IIS control the password and typed in the correct
> > > password.
> > > > 4) change the asp.net user that the install of vs.net added and added
> them
> > > to the admin group on both machines. I have no problem login into sql
> > > server
> > > (windows authentication) when i use my local account i created on the xp
> > > workstation for me (im in the admin group).
> > > > The only thing i have not used is impersonation and id rather not unless
> i
> > > have to. Course since i haven't tried it, i might have trouble with it
> > > too.
> > > > Scratch what i just said above. I tried impersonaltion and it worked but
> > > id
> > > rather not use this if at all possible. I want to use the security that
> > > vs.net set up for the "asp.net" user. Is this possible without using
> > > impersonation?
> > > > Thanks,
> > > Brent
> >
Just tried that...that doesn't work either.

"EC" <ec@.notmyrealaddress.com> wrote in message
news:OqqHtuX0EHA.3244@.TK2MSFTNGP10.phx.gbl...
> In this case, you need to add the IIS_WPG account to your database users.
> "Brent Waldrop" <brentwa@.spam.hotmail.com> wrote in message
> news:eDG6JRW0EHA.2976@.TK2MSFTNGP12.phx.gbl...
>> Actually Rob, SQL Server does. I created two identical user accounts on
>> both
>> the xp box and the windows 2003 box and used the same password. I can log
>> into query analyzer just fine using windows authentication. My sql server
>> is
>> set up to use only windows authentication so username/password does not
>> work
>> and i prefer to keep it this way. Also the server explorer works just
>> fine
>> under the VS.Net IDE. I appreciate your reply though. Also when i create
>> a
>> regular vb.net app; windows authentication works just fine.
>>
>> Brent
>> "Rob Bazinet" <rbazinet66@.hotmail.com> wrote in message
>> news:OXR%23uFW0EHA.416@.TK2MSFTNGP10.phx.gbl...
>> > What does your connection string look like? If you are on a workgroup
>> > and
>> > NOT in a domain your sql server is not going to know the requesting
>> > user.
>>> > Have you tried not using a trusted connection and use something like
>> > this
>> in
>> > your connection string:
>>> > Server=(local);Initial Catalog=pubs;User Id=sa;Password=
>>> > -Rob
>>> > "Brent Waldrop" <brentwa@.spam.hotmail.com> wrote in message
>> > news:uUMCZ1V0EHA.3236@.TK2MSFTNGP15.phx.gbl...
>> > > Ok everyone, i have been pulling my hair out on this one. I have been
>> > > working on it for 3 days with no sucess. This problem is occuring at
>> home
>> > > where i am running a workgroup. I have Windows 2003 Ent Server on
>> > > one
>> > > machine and windows xp sp2 on another. The db server is located on
>> > > the
>> > > Windows 2003 machine. I am working locally with asp.net 1.1 on the xp
>> > > workstation and the web server is also locally on the xp workstation.
>> > > Every
>> > > time i try to connect with the asp.net application to the database i
>> > > get
>> > > the
>> > > following error:
>> >> > > Server Error in '/WebApplication1' Application.
>>> > -----------------------
>> --
>> > > --
>> >> > > Login failed for user '(null)'. Reason: Not associated with a trusted
>> SQL
>> > > Server connection.
>> > > Description: An unhandled exception occurred during the execution of
>> > > the
>> > > current web request. Please review the stack trace for more
>> > > information
>> > > about the error and where it originated in the code.
>> >> > > Exception Details: System.Data.SqlClient.SqlException: Login failed
>> > > for
>> > > user
>> > > '(null)'. Reason: Not associated with a trusted SQL Server
>> > > connection.
>> >> > > Source Error:
>> >> >> > > Line 44:
>> > > Line 45: ' fill the dataset
>> > > Line 46: dataAdapter.Fill(ds, "Customers")
>> > > Line 47: Dim bldr As New SqlCommandBuilder(dataAdapter)
>> > > Line 48:
>> >> >> > > Source File: c:\inetpub\wwwroot\WebApplication1\WebForm1.aspx.v b
>> Line:
>> > > 46
>> >> > > Stack Trace:
>> >> >> > > [SqlException: Login failed for user '(null)'. Reason: Not associated
>> with
>> > > a
>> > > trusted SQL Server connection.]
>> > > System.Data.SqlClient.ConnectionPool.GetConnection (Boolean&
>> > > isInTransaction)
>> >> >> System.Data.SqlClient.SqlConnectionPoolManager.Get PooledConnection(SqlConnec
>> > > tionString options, Boolean& isInTransaction)
>> > > System.Data.SqlClient.SqlConnection.Open()
>> > > System.Data.Common.DbDataAdapter.QuietOpen(IDbConn ection
>> > > connection,
>> > > ConnectionState& originalState)
>> > > System.Data.Common.DbDataAdapter.FillFromCommand(O bject data, Int32
>> > > startRecord, Int32 maxRecords, String srcTable, IDbCommand command,
>> > > CommandBehavior behavior)
>> > > System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32
>> > > startRecord,
>> > > Int32 maxRecords, String srcTable, IDbCommand command,
>> > > CommandBehavior
>> > > behavior)
>> > > System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String
>> srcTable)
>> > > WebApplication1.WebForm1.Page_Load(Object sender, EventArgs e) in
>> > > c:\inetpub\wwwroot\WebApplication1\WebForm1.aspx.v b:46
>> > > System.Web.UI.Control.OnLoad(EventArgs e)
>> > > System.Web.UI.Control.LoadRecursive()
>> > > System.Web.UI.Page.ProcessRequestMain()
>> >> >> > > I have tried to following to fix the problem.
>> >> > > 1) Tried to add the asp.net user to sql server
>> >> > > 2) Removed tcp/ip from the connect types to sql server
>> >> > > 3) added a new user which i called "aspnetuser" to both computers
>> > > then
>> > > when
>> > > into anonymous logins on IIS and added this user as the anonymous
>> > > login
>> > > user
>> > > and unchecked the let IIS control the password and typed in the
>> > > correct
>> > > password.
>> >> > > 4) change the asp.net user that the install of vs.net added and added
>> them
>> > > to the admin group on both machines. I have no problem login into sql
>> > > server
>> > > (windows authentication) when i use my local account i created on the
>> > > xp
>> > > workstation for me (im in the admin group).
>> >> > > The only thing i have not used is impersonation and id rather not
>> > > unless
>> i
>> > > have to. Course since i haven't tried it, i might have trouble with
>> > > it
>> > > too.
>> >> > > Scratch what i just said above. I tried impersonaltion and it worked
>> > > but
>> > > id
>> > > rather not use this if at all possible. I want to use the security
>> > > that
>> > > vs.net set up for the "asp.net" user. Is this possible without using
>> > > impersonation?
>> >> > > Thanks,
>> > > Brent
>> >> >>>>
>>

Trouble binding a dropdown list in a detailsview.

Hi

On 17 Nov, 01:37, B. Chernick wrote:

Quote:

Originally Posted by

Sorry, actually no. If I move the code into the DetailView's DataBinding
event (or the screen's), the code fails entirely because it can't find the
ddl. Hasn't been rendered yet.


Milosz is right about the timing of the code causing the exception. In
insert mode, there is no attempt to automatically bind the selected
value of the ddl control to a field value because it's a new record,
whereas in Edit mode it tries to bind the selected value to the
current value of the field.

To get round this you'll have to delete the databinding between the
ddl and the datasource (in the edit mode template) and set the
selected value manually in code immediately after the code you have
already written. In the DataBound event, you can differentiate
betweeen the two modes using DetailsView1.CurrentMode() and make the
code for setting the ddl selected value conditonal upon that.

You'll also need to handle the update manually for the respective
datafield as well in the Updating event.

HTHThank you Milosz and Phil.

Out of town for the holiday but I continue this as soon as I get home Friday.

"Phil H" wrote:

Quote:

Originally Posted by

Hi
>
On 17 Nov, 01:37, B. Chernick wrote:

Quote:

Originally Posted by

Sorry, actually no. If I move the code into the DetailView's DataBinding
event (or the screen's), the code fails entirely because it can't find the
ddl. Hasn't been rendered yet.


>
Milosz is right about the timing of the code causing the exception. In
insert mode, there is no attempt to automatically bind the selected
value of the ddl control to a field value because it's a new record,
whereas in Edit mode it tries to bind the selected value to the
current value of the field.
>
To get round this you'll have to delete the databinding between the
ddl and the datasource (in the edit mode template) and set the
selected value manually in code immediately after the code you have
already written. In the DataBound event, you can differentiate
betweeen the two modes using DetailsView1.CurrentMode() and make the
code for setting the ddl selected value conditonal upon that.
>
You'll also need to handle the update manually for the respective
datafield as well in the Updating event.
>
HTH
>

Trouble binding a dropdown list in a detailsview.

Ok, I'm lost. I'm writing a webpage in VB/Dot Net 2.0 and I'm trying to put
a
dropdown list in a detailsview. The dropdownlist is supposed to display a
simple enum.
From what little I've seen so far, the place in VB code to bind a ddl is in
the detailview's databound event. Any earlier and you can't get a handle on
the ddl. The detailsview is essentially alone on it's page and is called in
either edit or insert mode only. (In the page lode, I examine a querystring
parameter and based on that, set the detailsview to either edit or insert
mode.) I have created template ddls in the column corresponding to this
variable. All existing records have valid values in this field (a smallint)
.
The code itself is routine:
ddlClassType = DetailsView1.FindControl("ddlClassType")
Dim names() As String = System.Enum.GetNames(GetType(ClassType))
Dim values() As Integer = System.Enum.GetValues(GetType(ClassType))
Dim i As Integer
For i = 0 To names.Length - 1
Dim item As New ListItem(names(i), values(i).ToString)
ddlClassType.Items.Add(item)
Next
This works fine for Inserts but the code never gets to this point for
updates. It crashes with the error: 'ddlClassType' has a SelectedValue whic
h
is invalid because it does not exist in the list of items. Parameter name:
value
Any suggestions?Howdy,
Moving population code into detail's DataBinding event should resolve the
problem. Take a look at your aspx code and notice, there's Bind or Eval
statement inside SelectedValue: SelectedValue='<%# Eval("WhatEver") %>' whic
h
expects items have already been populated. Unfortunatelly, you're populating
items afterwards, hence the exception.
hope this helps
--
Milosz
"B. Chernick" wrote:

> Ok, I'm lost. I'm writing a webpage in VB/Dot Net 2.0 and I'm trying to pu
t a
> dropdown list in a detailsview. The dropdownlist is supposed to display a
> simple enum.
> From what little I've seen so far, the place in VB code to bind a ddl is i
n
> the detailview's databound event. Any earlier and you can't get a handle
on
> the ddl. The detailsview is essentially alone on it's page and is called
in
> either edit or insert mode only. (In the page lode, I examine a querystrin
g
> parameter and based on that, set the detailsview to either edit or insert
> mode.) I have created template ddls in the column corresponding to this
> variable. All existing records have valid values in this field (a smallin
t).
>
> The code itself is routine:
> ddlClassType = DetailsView1.FindControl("ddlClassType")
> Dim names() As String = System.Enum.GetNames(GetType(ClassType))
> Dim values() As Integer = System.Enum.GetValues(GetType(ClassType))
> Dim i As Integer
> For i = 0 To names.Length - 1
> Dim item As New ListItem(names(i), values(i).ToString)
> ddlClassType.Items.Add(item)
> Next
> This works fine for Inserts but the code never gets to this point for
> updates. It crashes with the error: 'ddlClassType' has a SelectedValue wh
ich
> is invalid because it does not exist in the list of items. Parameter name:
> value
> Any suggestions?
>
Sorry, actually no. If I move the code into the DetailView's DataBinding
event (or the screen's), the code fails entirely because it can't find the
ddl. Hasn't been rendered yet.
I have a vague memory of populating a dropdown in my last job using
javascript and those <%# %> brackets, but I'm still digging through my notes
for that one. Have you ever done that?
"Milosz Skalecki [MCAD]" wrote:
> Howdy,
> Moving population code into detail's DataBinding event should resolve the
> problem. Take a look at your aspx code and notice, there's Bind or Eval
> statement inside SelectedValue: SelectedValue='<%# Eval("WhatEver") %>' wh
ich
> expects items have already been populated. Unfortunatelly, you're populati
ng
> items afterwards, hence the exception.
> hope this helps
> --
> Milosz
>
> "B. Chernick" wrote:
>
Many times. Paste the code.
--
Milosz
"B. Chernick" wrote:
> Sorry, actually no. If I move the code into the DetailView's DataBinding
> event (or the screen's), the code fails entirely because it can't find the
> ddl. Hasn't been rendered yet.
> I have a vague memory of populating a dropdown in my last job using
> javascript and those <%# %> brackets, but I'm still digging through my not
es
> for that one. Have you ever done that?
> "Milosz Skalecki [MCAD]" wrote:
>
Hi
On 17 Nov, 01:37, B. Chernick wrote:
> Sorry, actually no. If I move the code into the DetailView's DataBinding
> event (or the screen's), the code fails entirely because it can't find the
> ddl. Hasn't been rendered yet.
Milosz is right about the timing of the code causing the exception. In
insert mode, there is no attempt to automatically bind the selected
value of the ddl control to a field value because it's a new record,
whereas in Edit mode it tries to bind the selected value to the
current value of the field.
To get round this you'll have to delete the databinding between the
ddl and the datasource (in the edit mode template) and set the
selected value manually in code immediately after the code you have
already written. In the DataBound event, you can differentiate
betweeen the two modes using DetailsView1.CurrentMode() and make the
code for setting the ddl selected value conditonal upon that.
You'll also need to handle the update manually for the respective
datafield as well in the Updating event.
HTH
Thank you Milosz and Phil.
Out of town for the holiday but I continue this as soon as I get home Friday
.
"Phil H" wrote:

> Hi
> On 17 Nov, 01:37, B. Chernick wrote:
> Milosz is right about the timing of the code causing the exception. In
> insert mode, there is no attempt to automatically bind the selected
> value of the ddl control to a field value because it's a new record,
> whereas in Edit mode it tries to bind the selected value to the
> current value of the field.
> To get round this you'll have to delete the databinding between the
> ddl and the datasource (in the edit mode template) and set the
> selected value manually in code immediately after the code you have
> already written. In the DataBound event, you can differentiate
> betweeen the two modes using DetailsView1.CurrentMode() and make the
> code for setting the ddl selected value conditonal upon that.
> You'll also need to handle the update manually for the respective
> datafield as well in the Updating event.
> HTH
>
After some trial and error, I finally got it to work. Is this roughly what
you had in mind? (I first replaced the ddl in the edit template with a new
unbound dropdownlist.)
Private Sub DetailsView1_DataBound(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DetailsView1.DataBound
Dim names() As String = System.Enum.GetNames(GetType(ClassType))
Dim values() As Integer = System.Enum.GetValues(GetType(ClassType))
If DetailsView1.CurrentMode = DetailsViewMode.Edit Then
ddlClassType = DetailsView1.FindControl("ddlClassType")
Dim i As Integer
For i = 0 To names.Length - 1
Dim item As New ListItem(names(i), values(i).ToString)
ddlClassType.Items.Add(item)
Next
' Set incoming value
Dim dr As DataRowView
dr = DetailsView1.DataItem
ddlClassType.SelectedValue = dr.Item("ClassType").ToString
End If
End Sub
Private Sub ObjectDataSource1_Updating(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs) Handles
ObjectDataSource1.Updating
' manually update values here
ddlClassType = DetailsView1.FindControl("ddlClassType")
e.InputParameters.Item("ClassType") = ddlClassType.SelectedValue
End Sub
"Phil H" wrote:

> Hi
> On 17 Nov, 01:37, B. Chernick wrote:
> Milosz is right about the timing of the code causing the exception. In
> insert mode, there is no attempt to automatically bind the selected
> value of the ddl control to a field value because it's a new record,
> whereas in Edit mode it tries to bind the selected value to the
> current value of the field.
> To get round this you'll have to delete the databinding between the
> ddl and the datasource (in the edit mode template) and set the
> selected value manually in code immediately after the code you have
> already written. In the DataBound event, you can differentiate
> betweeen the two modes using DetailsView1.CurrentMode() and make the
> code for setting the ddl selected value conditonal upon that.
> You'll also need to handle the update manually for the respective
> datafield as well in the Updating event.
> HTH
>

trouble binding a datagrid to a custom collection

I'm trying to bind a custom collection to an autogenerated datagrid without
success.
I'm getting this error:
DataGrid with id 'DataGrid2' could not automatically generate any columns
from the selected data source.
Could you help me to find a solution? What is the problem in my code? Thanks
.
Here is my code (NewsContent.aspx):
<form id="Form1" method="post" runat="server">
<asp:DataGrid id="DataGrid2" runat="server"></asp:DataGrid>
</form>
//----
Code behind:(NewsContent.aspx.cs).
public class NewsContent{
private void Page_Load(object sender, System.EventArgs e)
{
ListItemCollection myListCollection = AddToCustomCollection();
this.DataGrid2.DataSource = myListCollection;
this.DataGrid2.DataBind();
}
private ListItemCollection AddToCustomCollection()
{
ListItemCollection myListCollection = new ListItemCollection();
NewsContent.NewsItem myItem1 = new NewsContent.NewsItem("viko", "url1",
"today");
NewsContent.NewsItem myItem2 = new NewsContent.NewsItem("vikan", "url2",
"imorgon");
NewsContent.NewsItem myItem3 = new NewsContent.NewsItem("kiki", "url3",
"veckan");
myListCollection.Add(myItem1);
myListCollection.Add(myItem2);
myListCollection.Add(myItem3);
return myListCollection;
}
//Inner Class which holds all properties needed to show news content and
listings
public class NewsItem
{
public NewsItem()
{
}
public NewsItem(string linkName, string linkUrl, string date)
{
}
public string linkName;
public string linkUrl;
public string date;
public string longDate;
}
}
//----
--
I'm using a collection class: (ListItemCollection.cs):
public class ListItemCollection:CollectionBase
{
public ListItemCollection()
{
//
// TODO: Add constructor logic here
//
}
public NewsContent.NewsItem Item(int index)
{
//the appropiate item is retrieved from the list object and
//explicitly cast to the ListItem type, then returned to the
//caller
return (NewsContent.NewsItem) List[index];
}
public int Add(NewsContent.NewsItem myNewsItem)
{
return List.Add(myNewsItem);
}
}Try setting the autogeneratecolumn property for this datagrid to True.
"viktor9990" wrote:

> I'm trying to bind a custom collection to an autogenerated datagrid withou
t
> success.
> I'm getting this error:
> DataGrid with id 'DataGrid2' could not automatically generate any columns
> from the selected data source.
> Could you help me to find a solution? What is the problem in my code? Than
ks.
> Here is my code (NewsContent.aspx):
> <form id="Form1" method="post" runat="server">
> <asp:DataGrid id="DataGrid2" runat="server"></asp:DataGrid>
> </form>
> //----
> Code behind:(NewsContent.aspx.cs).
> public class NewsContent{
> private void Page_Load(object sender, System.EventArgs e)
> {
> ListItemCollection myListCollection = AddToCustomCollection();
> this.DataGrid2.DataSource = myListCollection;
> this.DataGrid2.DataBind();
> }
> private ListItemCollection AddToCustomCollection()
> {
> ListItemCollection myListCollection = new ListItemCollection();
> NewsContent.NewsItem myItem1 = new NewsContent.NewsItem("viko", "url1",
> "today");
> NewsContent.NewsItem myItem2 = new NewsContent.NewsItem("vikan", "url2"
,
> "imorgon");
> NewsContent.NewsItem myItem3 = new NewsContent.NewsItem("kiki", "url3",
> "veckan");
> myListCollection.Add(myItem1);
> myListCollection.Add(myItem2);
> myListCollection.Add(myItem3);
> return myListCollection;
> }
> //Inner Class which holds all properties needed to show news content and
> listings
> public class NewsItem
> {
> public NewsItem()
> {
> }
> public NewsItem(string linkName, string linkUrl, string date)
> {
> }
> public string linkName;
> public string linkUrl;
> public string date;
> public string longDate;
> }
> }
> //---
--
>
> I'm using a collection class: (ListItemCollection.cs):
> public class ListItemCollection:CollectionBase
> {
> public ListItemCollection()
> {
> //
> // TODO: Add constructor logic here
> //
> }
>
> public NewsContent.NewsItem Item(int index)
> {
> //the appropiate item is retrieved from the list object and
> //explicitly cast to the ListItem type, then returned to the
> //caller
> return (NewsContent.NewsItem) List[index];
> }
>
> public int Add(NewsContent.NewsItem myNewsItem)
> {
> return List.Add(myNewsItem);
> }
> }

trouble binding a datagrid to a custom collection

I'm trying to bind a custom collection to an autogenerated datagrid without
success.
I'm getting this error:

DataGrid with id 'DataGrid2' could not automatically generate any columns
from the selected data source.
Could you help me to find a solution? What is the problem in my code? Thanks.

Here is my code (NewsContent.aspx):
<form id="Form1" method="post" runat="server">
<asp:DataGrid id="DataGrid2" runat="server"></asp:DataGrid>
</form
//---------------------

Code behind:(NewsContent.aspx.cs).
public class NewsContent{

private void Page_Load(object sender, System.EventArgs e)
{

ListItemCollection myListCollection = AddToCustomCollection();
this.DataGrid2.DataSource = myListCollection;
this.DataGrid2.DataBind();
}

private ListItemCollection AddToCustomCollection()
{

ListItemCollection myListCollection = new ListItemCollection();
NewsContent.NewsItem myItem1 = new NewsContent.NewsItem("viko", "url1",
"today");
NewsContent.NewsItem myItem2 = new NewsContent.NewsItem("vikan", "url2",
"imorgon");
NewsContent.NewsItem myItem3 = new NewsContent.NewsItem("kiki", "url3",
"veckan");
myListCollection.Add(myItem1);
myListCollection.Add(myItem2);
myListCollection.Add(myItem3);

return myListCollection;
}

//Inner Class which holds all properties needed to show news content and
listings
public class NewsItem
{
public NewsItem()
{
}
public NewsItem(string linkName, string linkUrl, string date)
{
}
public string linkName;
public string linkUrl;
public string date;
public string longDate;
}
}

//------------------------

I'm using a collection class: (ListItemCollection.cs):

public class ListItemCollection:CollectionBase
{
public ListItemCollection()
{
//
// TODO: Add constructor logic here
//
}

public NewsContent.NewsItem Item(int index)
{
//the appropiate item is retrieved from the list object and
//explicitly cast to the ListItem type, then returned to the
//caller
return (NewsContent.NewsItem) List[index];
}

public int Add(NewsContent.NewsItem myNewsItem)
{
return List.Add(myNewsItem);
}

}Try setting the autogeneratecolumn property for this datagrid to True.

"viktor9990" wrote:

> I'm trying to bind a custom collection to an autogenerated datagrid without
> success.
> I'm getting this error:
> DataGrid with id 'DataGrid2' could not automatically generate any columns
> from the selected data source.
> Could you help me to find a solution? What is the problem in my code? Thanks.
> Here is my code (NewsContent.aspx):
> <form id="Form1" method="post" runat="server">
> <asp:DataGrid id="DataGrid2" runat="server"></asp:DataGrid>
> </form>
> //---------------------
> Code behind:(NewsContent.aspx.cs).
> public class NewsContent{
> private void Page_Load(object sender, System.EventArgs e)
> {
> ListItemCollection myListCollection = AddToCustomCollection();
> this.DataGrid2.DataSource = myListCollection;
> this.DataGrid2.DataBind();
> }
> private ListItemCollection AddToCustomCollection()
> {
> ListItemCollection myListCollection = new ListItemCollection();
> NewsContent.NewsItem myItem1 = new NewsContent.NewsItem("viko", "url1",
> "today");
> NewsContent.NewsItem myItem2 = new NewsContent.NewsItem("vikan", "url2",
> "imorgon");
> NewsContent.NewsItem myItem3 = new NewsContent.NewsItem("kiki", "url3",
> "veckan");
> myListCollection.Add(myItem1);
> myListCollection.Add(myItem2);
> myListCollection.Add(myItem3);
> return myListCollection;
> }
> //Inner Class which holds all properties needed to show news content and
> listings
> public class NewsItem
> {
> public NewsItem()
> {
> }
> public NewsItem(string linkName, string linkUrl, string date)
> {
> }
> public string linkName;
> public string linkUrl;
> public string date;
> public string longDate;
> }
> }
> //------------------------
>
> I'm using a collection class: (ListItemCollection.cs):
> public class ListItemCollection:CollectionBase
> {
> public ListItemCollection()
> {
> //
> // TODO: Add constructor logic here
> //
> }
>
> public NewsContent.NewsItem Item(int index)
> {
> //the appropiate item is retrieved from the list object and
> //explicitly cast to the ListItem type, then returned to the
> //caller
> return (NewsContent.NewsItem) List[index];
> }
>
> public int Add(NewsContent.NewsItem myNewsItem)
> {
> return List.Add(myNewsItem);
> }
> }