Showing posts with label sql. Show all posts
Showing posts with label sql. Show all posts

Saturday, March 31, 2012

Trimming spaces with calendar picker to send to sql statement

I have a Calendar PIcker that we choose a date from and send that out as a parameter to a sql statement. I have created my page in the visual studio designer and what I want to do is send is

RTrim(Calendar1.SelectedDate.ToShortDateString). My problem is since this was created in designer the code is all hidden. I can't place the RTrim() anywhere to accomplish this. Or maybe this whole process needs to be hard coded. It seems to me in VS 2003 you would see all the code thru expanding regions.

Thanks

Hey,

It should be there in the regions; I don't know how you are doing this; if you place it as an expression in the page, it could be in the page HTML. But how are you doing this? I need a little more info...

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 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 connecting to an SQL database in C#

Hi guys,

I'm using Visual Web Developer and I've made a GridView and I want to learn how to display information in it (or any other databound control) rather than doing it through the asp source code. I'm using the following code so far, and although I've probably made some errors in it I think there is a problem connecting to the database remotely as I get the following error on the "myConnection.Open()" line.

An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

I tried following the instructions here http://www.datamasker.com/SSE2005_NetworkCfg.htm but didn't have much luck as I don't seem to have the interface shown in the screen prints.

My code so far is

SqlConnection myConnection = new SqlConnection("Server=local;database=WroxUnited");
SqlCommand myCommand = new SqlCommand("SELECT * FROM [Fixtures]", myConnection);

myConnection.Open();

GridView1.DataSource = myCommand.ExecuteReader();
GridView1.DataBind();

myConnection.Close();

Thanks in advance.You specified a server (Local) and a database (WroxUnited) ... just so that we're on the same page, that isn't a remote DB... it's local on your PC.

But the problem is probably because you didn't specify an authentication method... do you intend to use integrated security (using WIndows Authentication) or to use SQL Server Authentication? IF you want integrated securtity then you need to add "Integrated Security=SSPI;" to the connection string otherwise add "Integrated Security=False;User ID=XXXXXX;Password=YYYYYYYY;"

-tg
You can make use of the idea in this code:

SqlConnection sc1 = new SqlConnectionConfigurationManager.ConnectionStrings ["CompanyConnectionString"].ToString ());
SqlDataAdapter sa1 = new SqlDataAdapter();
sc1.Open();
string c = "Select Name , Postion_Name from Employee join Postion on Postion_Num=Postion_ID";
SqlCommand sqc1 = new SqlCommand(c,sc1);
DataSet ds = new DataSet();
sa1.SelectCommand = sqc1;
sa1.Fill(ds);
GridView1.DataSource = ds;
What's annoying is there seems to be so many different ways to go about it, and as I'm just beginning to learn .NET it's all a bit confusing. I'm sure I'll get it eventually but I'm worried I may have already got it but something's not set up correctly to work. However if I do it through ASP source code using a ConnectionString=<%$ConnectionStrings=WroxUnited%> for example then it does work so I suppose it's unlikely to be a problem with the SQL Server set-up.

Just to test that it does actually work would someone be kind enough to post here the smallest amount of code necessary to display data from a database called WroxUnited.mdf stored in the C:, in a gridview called GridView1? Or if it's easier to use another data control then let me know and I'll do it that way.

Thanks for all the help!

trouble connecting to remote SQL server for authentication

I've got an app which provides data based on the user who is logged in.
So, I need the user data to be on the same db server as the other
data. I'm trying to do this using the membership API. I've set up the
tables and sprocs and so forth using the aspnet_regsql.exe (though, for
some reason, I had to do it using windows authentication rather than
using a SQL server account). I've modified the web.config file as
follows
<?xml version="1.0" encoding="utf-8"?>
<configuration
xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<connectionStrings>
<add name="SLAR-con" connectionString="Data
Source=mySQLserver;Initial Catalog=SLAR;User
Id=mydomain\myuserid;Password=mypassword
" />
</connectionStrings>
<system.web>
<roleManager enabled="true" />
<authentication mode="Forms" />
<membership>
<providers>
<add connectionStringName="SLAR-con"
applicationName="SLAR" minRequiredPasswordLength="5"
minRequiredNonalphanumericCharacters="0"
name="CustomizedProvider"
type="System.Web.Security.SqlMembershipProvider" />
</providers>
</membership>
</system.web>
</configuration>
and I've tested the login and it seems to be working. However, when I
go into the database on the SQL server to look at the user I created,
the user authentication tables are all empty. The data isn't being
stored on the SQL server where I want it to be (I'm assuming it is
being stored in a SQL Server express database on the local machine).
How do I get the data to be stored in the remote SQL server?
----
--Check both databases and make sure it is not pointiong locally. As long as
machine name is correct, you should be on the other server.
NOTE: SQL Server 2005 requires SQL Browser on to connect remotely. You also
have to have proper transports set up, as some versions install without
TCP/IP or named pipes on.
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com
****************************************
*********
Think outside of the box!
****************************************
*********
<brian.newman@.wpafb.af.mil> wrote in message
news:1161862621.467371.69570@.i3g2000cwc.googlegroups.com...
> I've got an app which provides data based on the user who is logged in.
> So, I need the user data to be on the same db server as the other
> data. I'm trying to do this using the membership API. I've set up the
> tables and sprocs and so forth using the aspnet_regsql.exe (though, for
> some reason, I had to do it using windows authentication rather than
> using a SQL server account). I've modified the web.config file as
> follows
> <?xml version="1.0" encoding="utf-8"?>
> <configuration
> xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
> <connectionStrings>
> <add name="SLAR-con" connectionString="Data
> Source=mySQLserver;Initial Catalog=SLAR;User
> Id=mydomain\myuserid;Password=mypassword
" />
> </connectionStrings>
> <system.web>
> <roleManager enabled="true" />
> <authentication mode="Forms" />
> <membership>
> <providers>
> <add connectionStringName="SLAR-con"
> applicationName="SLAR" minRequiredPasswordLength="5"
> minRequiredNonalphanumericCharacters="0"
> name="CustomizedProvider"
> type="System.Web.Security.SqlMembershipProvider" />
> </providers>
> </membership>
>
> </system.web>
> </configuration>
> and I've tested the login and it seems to be working. However, when I
> go into the database on the SQL server to look at the user I created,
> the user authentication tables are all empty. The data isn't being
> stored on the SQL server where I want it to be (I'm assuming it is
> being stored in a SQL Server express database on the local machine).
> How do I get the data to be stored in the remote SQL server?
>
> ----
--
>
Cowboy (Gregory A. Beamer) wrote:
> Check both databases and make sure it is not pointiong locally. As long as
> machine name is correct, you should be on the other server.
> NOTE: SQL Server 2005 requires SQL Browser on to connect remotely. You als
o
> have to have proper transports set up, as some versions install without
> TCP/IP or named pipes on.
> --
> Gregory A. Beamer
> MVP; MCP: +I, SE, SD, DBA
> http://gregorybeamer.spaces.live.com
> ****************************************
*********
> Think outside of the box!
> ****************************************
*********
> <brian.newman@.wpafb.af.mil> wrote in message
> news:1161862621.467371.69570@.i3g2000cwc.googlegroups.com...
It is being stored locally (local to the machine on which I'm doing the
development), but I'm unclear on how to point it to the SQL server db.
I thought the edits shown in the top post I made to the web.config file
would handle that, but they don't. The SQL server db is SQL Server
2000.
By the way, thanks for the assist. I posted on Microsoft asp.net forum
and got 20 views, but no assist and got nothing from 4guysfromrolla.

trouble connecting to remote SQL server for authentication

I've got an app which provides data based on the user who is logged in.
So, I need the user data to be on the same db server as the other
data. I'm trying to do this using the membership API. I've set up the
tables and sprocs and so forth using the aspnet_regsql.exe (though, for
some reason, I had to do it using windows authentication rather than
using a SQL server account). I've modified the web.config file as
follows

<?xml version="1.0" encoding="utf-8"?>

<configuration
xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">

<connectionStrings>

<add name="SLAR-con" connectionString="Data
Source=mySQLserver;Initial Catalog=SLAR;User
Id=mydomain\myuserid;Password=mypassword" />

</connectionStrings>

<system.web>

<roleManager enabled="true" />

<authentication mode="Forms" />

<membership>

<providers>

<add connectionStringName="SLAR-con"
applicationName="SLAR" minRequiredPasswordLength="5"

minRequiredNonalphanumericCharacters="0"
name="CustomizedProvider"

type="System.Web.Security.SqlMembershipProvider" />

</providers>

</membership>

</system.web>

</configuration>

and I've tested the login and it seems to be working. However, when I
go into the database on the SQL server to look at the user I created,
the user authentication tables are all empty. The data isn't being
stored on the SQL server where I want it to be (I'm assuming it is
being stored in a SQL Server express database on the local machine).
How do I get the data to be stored in the remote SQL server?

------------------------Check both databases and make sure it is not pointiong locally. As long as
machine name is correct, you should be on the other server.

NOTE: SQL Server 2005 requires SQL Browser on to connect remotely. You also
have to have proper transports set up, as some versions install without
TCP/IP or named pipes on.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com
*************************************************
Think outside of the box!
*************************************************
<brian.newman@.wpafb.af.milwrote in message
news:1161862621.467371.69570@.i3g2000cwc.googlegrou ps.com...

Quote:

Originally Posted by

I've got an app which provides data based on the user who is logged in.
So, I need the user data to be on the same db server as the other
data. I'm trying to do this using the membership API. I've set up the
tables and sprocs and so forth using the aspnet_regsql.exe (though, for
some reason, I had to do it using windows authentication rather than
using a SQL server account). I've modified the web.config file as
follows
>
<?xml version="1.0" encoding="utf-8"?>
>
<configuration
xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
>
<connectionStrings>
>
<add name="SLAR-con" connectionString="Data
Source=mySQLserver;Initial Catalog=SLAR;User
Id=mydomain\myuserid;Password=mypassword" />
>
</connectionStrings>
>
<system.web>
>
<roleManager enabled="true" />
>
<authentication mode="Forms" />
>
<membership>
>
<providers>
>
<add connectionStringName="SLAR-con"
applicationName="SLAR" minRequiredPasswordLength="5"
>
minRequiredNonalphanumericCharacters="0"
name="CustomizedProvider"
>
type="System.Web.Security.SqlMembershipProvider" />
>
</providers>
>
</membership>
>
>
>
</system.web>
>
</configuration>
>
and I've tested the login and it seems to be working. However, when I
go into the database on the SQL server to look at the user I created,
the user authentication tables are all empty. The data isn't being
stored on the SQL server where I want it to be (I'm assuming it is
being stored in a SQL Server express database on the local machine).
How do I get the data to be stored in the remote SQL server?
>
>
------------------------
>


Cowboy (Gregory A. Beamer) wrote:

Quote:

Originally Posted by

Check both databases and make sure it is not pointiong locally. As long as
machine name is correct, you should be on the other server.
>
NOTE: SQL Server 2005 requires SQL Browser on to connect remotely. You also
have to have proper transports set up, as some versions install without
TCP/IP or named pipes on.
>
--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com
>
*************************************************
Think outside of the box!
*************************************************
<brian.newman@.wpafb.af.milwrote in message
news:1161862621.467371.69570@.i3g2000cwc.googlegrou ps.com...

Quote:

Originally Posted by

I've got an app which provides data based on the user who is logged in.
So, I need the user data to be on the same db server as the other
data. I'm trying to do this using the membership API. I've set up the
tables and sprocs and so forth using the aspnet_regsql.exe (though, for
some reason, I had to do it using windows authentication rather than
using a SQL server account). I've modified the web.config file as
follows

<?xml version="1.0" encoding="utf-8"?>

<configuration
xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">

<connectionStrings>

<add name="SLAR-con" connectionString="Data
Source=mySQLserver;Initial Catalog=SLAR;User
Id=mydomain\myuserid;Password=mypassword" />

</connectionStrings>

<system.web>

<roleManager enabled="true" />

<authentication mode="Forms" />

<membership>

<providers>

<add connectionStringName="SLAR-con"
applicationName="SLAR" minRequiredPasswordLength="5"

minRequiredNonalphanumericCharacters="0"
name="CustomizedProvider"

type="System.Web.Security.SqlMembershipProvider" />

</providers>

</membership>

</system.web>

</configuration>

and I've tested the login and it seems to be working. However, when I
go into the database on the SQL server to look at the user I created,
the user authentication tables are all empty. The data isn't being
stored on the SQL server where I want it to be (I'm assuming it is
being stored in a SQL Server express database on the local machine).
How do I get the data to be stored in the remote SQL server?

------------------------


It is being stored locally (local to the machine on which I'm doing the
development), but I'm unclear on how to point it to the SQL server db.
I thought the edits shown in the top post I made to the web.config file
would handle that, but they don't. The SQL server db is SQL Server
2000.
By the way, thanks for the assist. I posted on Microsoft asp.net forum
and got 20 views, but no assist and got nothing from 4guysfromrolla.

Monday, March 26, 2012

Trouble opening a connection to SQL 2000 DB

I'm developing an intranet site in ASP.NET 2.0 but I can't seem to
connect to the DB from within my code. I've created a .vb class that
houses a private Connection() that other functions within the class can
call to connect to the database. In the calling function, I've declared
my connection object and called the "Open" method on the object.
However, when I attempt to execute the stored procedure command by
calling the "ExecuteScalar" method, I get the following error:
"ExecuteScalar requires an open and available Connection. The
connection's current state is closed."
Here's the code from my class:
Imports System.Data
Imports System.Data.SqlClient
Namespace Encompass
Public Class EncompassSecurity
Public Shared Function GetHRIDByNTUserID(ByVal strNTUserID) As String
Dim strHRID As String
'Create command object
Dim cmd As New SqlCommand("usp_Get_HRID_By_NTUserID", Connection())
cmd.CommandType = CommandType.StoredProcedure
'Open DB connection
Dim DBConnection As SqlConnection = Connection()
DBConnection.Open()
'Input parameters
Dim inNTUserParam As New SqlParameter("@dotnet.itags.org.NT_UserID", SqlDbType.VarChar)
inNTUserParam.Direction = ParameterDirection.Input
inNTUserParam.Value = strNTUserID
cmd.Parameters.Add(inNTUserParam)
'Output parameters
Dim outHRIDParam As New SqlParameter("@dotnet.itags.org.HRID", SqlDbType.Int)
outHRIDParam.Direction = ParameterDirection.Output
cmd.Parameters.Add(outHRIDParam)
'Run stored procedure
strHRID = cmd.ExecuteScalar()
Return (strHRID)
'Close DB connection
DBConnection.Close()
End Function
Private Shared Function Connection() As SqlConnection
Dim strConnectionString As String
strConnectionString = ConfigurationManager.ConnectionStrings(
"Conn").ConnectionString
Return New SqlConnection(strConnectionString)
End Function
End Class
End
Namespace
Here's the code from my web.config file:
<?
xml version="1.0"?>
<!--
Note: As an alternative to hand editing this file you can use the
web admin tool to configure settings for your application. Use
the Website->Asp.Net Configuration option in Visual Studio.
A full list of settings and comments can be found in
machine.config.comments usually located in
\Windows\Microsoft.Net\Framework\v2.x\Config
-->
<
configuration
xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<
connectionStrings>
<
add name="Conn" connectionString="Data Source=ServerName;Initial
Catalog=NPASDV;uid=UserName;password=***
****;"
providerName="System.Data.SqlClient" />
</
connectionStrings>
<system.web>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
Visual Basic options:
Set strict="true" to disallow all data type conversions
where data loss can occur.
Set explicit="true" to force declaration of all variables.
-->
<
roleManager defaultProvider="AspNetWindowsTokenRoleProvider" />
<
compilation debug="true" strict="false" explicit="true" />
<
pages>
<
namespaces>
<
clear />
<
add namespace="System" />
<
add namespace="System.Collections" />
<
add namespace="System.Collections.Specialized" />
<
add namespace="System.Configuration" />
<
add namespace="System.Text" />
<
add namespace="System.Text.RegularExpressions" />
<
add namespace="System.Web" />
<
add namespace="System.Web.Caching" />
<
add namespace="System.Web.SessionState" />
<
add namespace="System.Web.Security" />
<
add namespace="System.Web.Profile" />
<
add namespace="System.Web.UI" />
<
add namespace="System.Web.UI.WebControls" />
<
add namespace="System.Web.UI.WebControls.WebParts" />
<
add namespace="System.Web.UI.HtmlControls" />
</
namespaces>
</
pages>
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<
authentication mode="Windows" />
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
</
system.web>
</
configuration>
What am I doing wrong? Any help would be most appreciated!!
Manuel Garr, MCPYou have created a Commad object with a connection object which is not open
yet.
Dim DBConnection As SqlConnection = Connection()
DBConnection.Open()
Dim cmd As New SqlCommand("usp_Get_HRID_By_NTUserID", DBConnection)
cmd.CommandType = CommandType.StoredProcedure
"mlg1906" <mlg1906@.discussions.microsoft.com> wrote in message
news:86C67AB7-8F4E-42A4-B0C8-CB7FC7DE7CD6@.microsoft.com...
> I'm developing an intranet site in ASP.NET 2.0 but I can't seem to
> connect to the DB from within my code. I've created a .vb class that
> houses a private Connection() that other functions within the class can
> call to connect to the database. In the calling function, I've declared
> my connection object and called the "Open" method on the object.
> However, when I attempt to execute the stored procedure command by
> calling the "ExecuteScalar" method, I get the following error:
> "ExecuteScalar requires an open and available Connection. The
> connection's current state is closed."
>
> Here's the code from my class:
>
> Imports System.Data
> Imports System.Data.SqlClient
>
> Namespace Encompass
>
> Public Class EncompassSecurity
>
> Public Shared Function GetHRIDByNTUserID(ByVal strNTUserID) As String
>
> Dim strHRID As String
>
> 'Create command object
>
> Dim cmd As New SqlCommand("usp_Get_HRID_By_NTUserID", Connection())
> cmd.CommandType = CommandType.StoredProcedure
>
> 'Open DB connection
>
> Dim DBConnection As SqlConnection = Connection()
> DBConnection.Open()
>
> 'Input parameters
>
> Dim inNTUserParam As New SqlParameter("@.NT_UserID", SqlDbType.VarChar)
> inNTUserParam.Direction = ParameterDirection.Input
>
> inNTUserParam.Value = strNTUserID
>
> cmd.Parameters.Add(inNTUserParam)
>
> 'Output parameters
>
> Dim outHRIDParam As New SqlParameter("@.HRID", SqlDbType.Int)
> outHRIDParam.Direction = ParameterDirection.Output
>
> cmd.Parameters.Add(outHRIDParam)
>
> 'Run stored procedure
> strHRID = cmd.ExecuteScalar()
>
> Return (strHRID)
>
> 'Close DB connection
> DBConnection.Close()
>
> End Function
>
> Private Shared Function Connection() As SqlConnection
>
> Dim strConnectionString As String
> strConnectionString = ConfigurationManager.ConnectionStrings(
>
> "Conn").ConnectionString
>
> Return New SqlConnection(strConnectionString)
>
> End Function
>
> End Class
> End
>
> Namespace
> Here's the code from my web.config file:
>
> <?
>
> xml version="1.0"?>
> <!--
>
> Note: As an alternative to hand editing this file you can use the
>
> web admin tool to configure settings for your application. Use
>
> the Website->Asp.Net Configuration option in Visual Studio.
>
> A full list of settings and comments can be found in
>
> machine.config.comments usually located in
>
> \Windows\Microsoft.Net\Framework\v2.x\Config
>
> -->
>
> <
>
> configuration
> xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
> <
>
> connectionStrings>
> <
>
> add name="Conn" connectionString="Data Source=ServerName;Initial
> Catalog=NPASDV;uid=UserName;password=***
****;"
>
> providerName="System.Data.SqlClient" />
> </
>
> connectionStrings>
>
> <system.web>
> <!--
>
> Set compilation debug="true" to insert debugging
>
> symbols into the compiled page. Because this
>
> affects performance, set this value to true only
>
> during development.
>
> Visual Basic options:
>
> Set strict="true" to disallow all data type conversions
>
> where data loss can occur.
>
> Set explicit="true" to force declaration of all variables.
>
> -->
> <
>
> roleManager defaultProvider="AspNetWindowsTokenRoleProvider" />
> <
>
> compilation debug="true" strict="false" explicit="true" />
> <
>
> pages>
> <
>
> namespaces>
> <
>
> clear />
> <
>
> add namespace="System" />
> <
>
> add namespace="System.Collections" />
> <
>
> add namespace="System.Collections.Specialized" />
> <
>
> add namespace="System.Configuration" />
> <
>
> add namespace="System.Text" />
> <
>
> add namespace="System.Text.RegularExpressions" />
> <
>
> add namespace="System.Web" />
> <
>
> add namespace="System.Web.Caching" />
> <
>
> add namespace="System.Web.SessionState" />
> <
>
> add namespace="System.Web.Security" />
> <
>
> add namespace="System.Web.Profile" />
> <
>
> add namespace="System.Web.UI" />
> <
>
> add namespace="System.Web.UI.WebControls" />
> <
>
> add namespace="System.Web.UI.WebControls.WebParts" />
> <
>
> add namespace="System.Web.UI.HtmlControls" />
> </
>
> namespaces>
> </
>
> pages>
> <!--
>
> The <authentication> section enables configuration
>
> of the security authentication mode used by
>
> ASP.NET to identify an incoming user.
>
> -->
> <
>
> authentication mode="Windows" />
>
> <!--
>
> The <customErrors> section enables configuration
>
> of what to do if/when an unhandled error occurs
>
> during the execution of a request. Specifically,
>
> it enables developers to configure html error pages
>
> to be displayed in place of a error stack trace.
>
> <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
>
> <error statusCode="403" redirect="NoAccess.htm" />
>
> <error statusCode="404" redirect="FileNotFound.htm" />
>
> </customErrors>
>
> -->
> </
>
> system.web>
> </
>
> configuration>
> What am I doing wrong? Any help would be most appreciated!!
>
> --
> Manuel Garr, MCP
>
Winista wrote:
> You have created a Commad object with a connection object which is not ope
n
> yet.
> Dim DBConnection As SqlConnection = Connection()
> DBConnection.Open()
> Dim cmd As New SqlCommand("usp_Get_HRID_By_NTUserID", DBConnection)
> cmd.CommandType = CommandType.StoredProcedure
>
A command object can be created without the connection being opened.
However, your code is partially correct. The only thing that needs to
be changed is the call to DBConnection.Open() should be made right
before the cmd.ExecuteScalar() call.
> "mlg1906" <mlg1906@.discussions.microsoft.com> wrote in message
> news:86C67AB7-8F4E-42A4-B0C8-CB7FC7DE7CD6@.microsoft.com...
--
Manuel
"Winista" wrote:
> You have created a Commad object with a connection object which is not ope
n
> yet.
> Dim DBConnection As SqlConnection = Connection()
> DBConnection.Open()
> Dim cmd As New SqlCommand("usp_Get_HRID_By_NTUserID", DBConnection)
> cmd.CommandType = CommandType.StoredProcedure
> "mlg1906" <mlg1906@.discussions.microsoft.com> wrote in message
> news:86C67AB7-8F4E-42A4-B0C8-CB7FC7DE7CD6@.microsoft.com...
Thanks for you help too!
--
Manuel
"tdavisjr" wrote:
> Winista wrote:
>
> A command object can be created without the connection being opened.
> However, your code is partially correct. The only thing that needs to
> be changed is the call to DBConnection.Open() should be made right
> before the cmd.ExecuteScalar() call.
>
>
>
Thanks so much for your help. It's working now.
--
Manuel
"Winista" wrote:
> You have created a Commad object with a connection object which is not ope
n
> yet.
> Dim DBConnection As SqlConnection = Connection()
> DBConnection.Open()
> Dim cmd As New SqlCommand("usp_Get_HRID_By_NTUserID", DBConnection)
> cmd.CommandType = CommandType.StoredProcedure
> "mlg1906" <mlg1906@.discussions.microsoft.com> wrote in message
> news:86C67AB7-8F4E-42A4-B0C8-CB7FC7DE7CD6@.microsoft.com...