By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,934 Members | 1,677 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,934 IT Pros & Developers. It's quick & easy.

Connecting to a sql server database

P: n/a

I have a client who is trying to connect to a sql server database using
asp.net and this is the error message that they get, any ideas on what is
causing the error message and what the correction for this.

Code they are using

<%@ Page Language="VB" Debug="true" %>

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<html>
<body>

<%
Dim Conn As SqlConnection = New SqlConnection()
Conn.ConnectionString = "Provider=SQLOLEDB;Data Source=blah;Initial
Catalog=blah;user id=blah;password=blah2;"
Conn.Open()
Dim cmdSelectSpecies as SqlCommand
Dim species_result as SqlDataReader

cmdSelectSpecies = New SqlCommand("SELECT SpeciesName FROM Species",Conn)
species_result = cmdSelectSpecies.ExecuteReader()
While species_result.Read()
Response.Write( "<li>" )
Response.Write( species_result( "SpeciesName" ) )
end While
species_result.close()
Conn.close()
%>
</body>
</html>
Error MEssage
Server Error in '/' Application.
----------------------------------------------------------------------------
----

Login failed for user 'NT AUTHORITY\NETWORK SERVICE'.
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 'NT AUTHORITY\NETWORK SERVICE'.

Source Error:
Line 11: "Initial Catalog=hekman_contract;" & _
Line 12: "Integrated Security=SSPI"
Line 13: Conn.Open()
Line 14:
Line 15:
Source File: c:\inetpub\wwwroot\hekman_contract\test.AW.aspx Line: 13

Stack Trace:
[SqlException: Login failed for user 'NT AUTHORITY\NETWORK SERVICE'.]
System.Data.SqlClient.ConnectionPool.GetConnection (Boolean&
isInTransaction)
+474
System.Data.SqlClient.SqlConnectionPoolManager.Get PooledConnection
(SqlConnectionString options, Boolean& isInTransaction) +372
System.Data.SqlClient.SqlConnection.Open() +384
ASP.test_AW_aspx.__Render__control1(HtmlTextWriter __output, Control
parameterContainer) in c:\inetpub\wwwroot\hekman_contract\test.AW.aspx:13
System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer) +27
System.Web.UI.Control.Render(HtmlTextWriter writer) +7
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
System.Web.UI.Page.ProcessRequestMain() +1926


----------------------------------------------------------------------------
----
Version Information: Microsoft .NET Framework Version:1.1.4322.2032; ASP.NET
Version:1.1.4322.2032

--
J.Daly
structure:interactive
Ph: 616-364-7423
Fx: 616-364-6941

http://www.structureinteractive.com

Jul 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
You are trying to use integrated security in your app (as is shown in the
line numbered code where the connection string is shown). This looks like
it's running on 2003 server, because asp.net runs under 'network service' by
default in this case. The 'network service' account doesn't have access to
sql server, hence integrated security fails.

The page source code you show is using a username/password to connect, but
clearly your client modifed the connection string to use integrated
security.

Don't write your code as asp.net script, since then your clients will start
modifying it in unpredictable ways, and you will have a support nightmare on
your hands. You should give them specific instructions on setting up a
username/password on their sql server and have them put this in web.config
or someplace like that, and have your app look there for connection
information. I also noticed you are using the old ASP method of writing out
all the HTML on your page - this is pretty antiquated. I would recommend you
take advantage of all the asp.net server controls now available to do this
sort of thing.
"Irishmaninusa"
<jd***@structuctureinteractive.com.takemeoffifyouw antoemailme> wrote in
message news:%2****************@TK2MSFTNGP15.phx.gbl...

I have a client who is trying to connect to a sql server database using
asp.net and this is the error message that they get, any ideas on what is
causing the error message and what the correction for this.

Code they are using

<%@ Page Language="VB" Debug="true" %>

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<html>
<body>

<%
Dim Conn As SqlConnection = New SqlConnection()
Conn.ConnectionString = "Provider=SQLOLEDB;Data Source=blah;Initial
Catalog=blah;user id=blah;password=blah2;"
Conn.Open()
Dim cmdSelectSpecies as SqlCommand
Dim species_result as SqlDataReader

cmdSelectSpecies = New SqlCommand("SELECT SpeciesName FROM Species",Conn)
species_result = cmdSelectSpecies.ExecuteReader()
While species_result.Read()
Response.Write( "<li>" )
Response.Write( species_result( "SpeciesName" ) )
end While
species_result.close()
Conn.close()
%>
</body>
</html>
Error MEssage
Server Error in '/' Application.
-------------------------------------------------------------------------- -- ----

Login failed for user 'NT AUTHORITY\NETWORK SERVICE'.
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 'NT AUTHORITY\NETWORK SERVICE'.

Source Error:
Line 11: "Initial Catalog=hekman_contract;" & _ Line 12: "Integrated Security=SSPI"
Line 13: Conn.Open()
Line 14:
Line 15:
Source File: c:\inetpub\wwwroot\hekman_contract\test.AW.aspx Line: 13

Stack Trace:
[SqlException: Login failed for user 'NT AUTHORITY\NETWORK SERVICE'.]
System.Data.SqlClient.ConnectionPool.GetConnection (Boolean&
isInTransaction)
+474
System.Data.SqlClient.SqlConnectionPoolManager.Get PooledConnection
(SqlConnectionString options, Boolean& isInTransaction) +372
System.Data.SqlClient.SqlConnection.Open() +384
ASP.test_AW_aspx.__Render__control1(HtmlTextWriter __output, Control
parameterContainer) in c:\inetpub\wwwroot\hekman_contract\test.AW.aspx:13
System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer) +27
System.Web.UI.Control.Render(HtmlTextWriter writer) +7
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
System.Web.UI.Page.ProcessRequestMain() +1926


-------------------------------------------------------------------------- -- ----
Version Information: Microsoft .NET Framework Version:1.1.4322.2032; ASP.NET Version:1.1.4322.2032

--
J.Daly
structure:interactive
Ph: 616-364-7423
Fx: 616-364-6941

http://www.structureinteractive.com

Jul 21 '05 #2

P: n/a
Thanks.
"Marina" <so*****@nospam.com> wrote in message
news:Oh**************@TK2MSFTNGP14.phx.gbl...
You are trying to use integrated security in your app (as is shown in the
line numbered code where the connection string is shown). This looks like
it's running on 2003 server, because asp.net runs under 'network service' by default in this case. The 'network service' account doesn't have access to sql server, hence integrated security fails.

The page source code you show is using a username/password to connect, but
clearly your client modifed the connection string to use integrated
security.

Don't write your code as asp.net script, since then your clients will start modifying it in unpredictable ways, and you will have a support nightmare on your hands. You should give them specific instructions on setting up a
username/password on their sql server and have them put this in web.config
or someplace like that, and have your app look there for connection
information. I also noticed you are using the old ASP method of writing out all the HTML on your page - this is pretty antiquated. I would recommend you take advantage of all the asp.net server controls now available to do this
sort of thing.
"Irishmaninusa"
<jd***@structuctureinteractive.com.takemeoffifyouw antoemailme> wrote in
message news:%2****************@TK2MSFTNGP15.phx.gbl...

I have a client who is trying to connect to a sql server database using
asp.net and this is the error message that they get, any ideas on what is causing the error message and what the correction for this.

Code they are using

<%@ Page Language="VB" Debug="true" %>

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<html>
<body>

<%
Dim Conn As SqlConnection = New SqlConnection()
Conn.ConnectionString = "Provider=SQLOLEDB;Data Source=blah;Initial
Catalog=blah;user id=blah;password=blah2;"
Conn.Open()
Dim cmdSelectSpecies as SqlCommand
Dim species_result as SqlDataReader

cmdSelectSpecies = New SqlCommand("SELECT SpeciesName FROM Species",Conn) species_result = cmdSelectSpecies.ExecuteReader()
While species_result.Read()
Response.Write( "<li>" )
Response.Write( species_result( "SpeciesName" ) )
end While
species_result.close()
Conn.close()
%>
</body>
</html>
Error MEssage
Server Error in '/' Application.
--------------------------------------------------------------------------
--
----

Login failed for user 'NT AUTHORITY\NETWORK SERVICE'.
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 'NT AUTHORITY\NETWORK SERVICE'.

Source Error:
Line 11: "Initial Catalog=hekman_contract;" & _
Line 12: "Integrated Security=SSPI"
Line 13: Conn.Open()
Line 14:
Line 15:
Source File: c:\inetpub\wwwroot\hekman_contract\test.AW.aspx Line: 13

Stack Trace:
[SqlException: Login failed for user 'NT AUTHORITY\NETWORK SERVICE'.]
System.Data.SqlClient.ConnectionPool.GetConnection (Boolean&
isInTransaction)
+474
System.Data.SqlClient.SqlConnectionPoolManager.Get PooledConnection
(SqlConnectionString options, Boolean& isInTransaction) +372
System.Data.SqlClient.SqlConnection.Open() +384
ASP.test_AW_aspx.__Render__control1(HtmlTextWriter __output, Control
parameterContainer) in

c:\inetpub\wwwroot\hekman_contract\test.AW.aspx:13 System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer) +27
System.Web.UI.Control.Render(HtmlTextWriter writer) +7
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +243
System.Web.UI.Page.ProcessRequestMain() +1926


--------------------------------------------------------------------------
--
----
Version Information: Microsoft .NET Framework Version:1.1.4322.2032;

ASP.NET
Version:1.1.4322.2032

--
J.Daly
structure:interactive
Ph: 616-364-7423
Fx: 616-364-6941

http://www.structureinteractive.com


Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.