newbie question (can't connect from asp.net 2.0 to SQL Express)

G

Guest

I've the following simple page:

===

<%@ Page Language="C#" Debug="true" %>

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

<html>

<script language="C#" runat="server">
void Page_Load(Object sender, EventArgs e)
{

SqlConnection myConnection = new
SqlConnection("server=localhost;database=nn;Trusted_Connection=Yes");
myConnection.Open();
}
</script>

</html>

===

When I try to Start the page I got the following error:

===
Server Error in '/' Application.
Named Pipes Provider: The system cannot find the file specified.
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: Named Pipes Provider:
The system cannot find the file specified.

Source Error:
Line 11:
Line 12: SqlConnection myConnection = new
SqlConnection("server=localhost;database=nn;Trusted_Connection=Yes");
Line 13: myConnection.Open();
Line 14: }
Line 15: </script>

Source File: f:\study2\site\Default.aspx Line: 13

Stack Trace:
[SqlException (0x80131904): Named Pipes Provider: The system cannot find the
file specified.
]
System.Data.ProviderBase.DbConnectionPool.GetConnection(Object
owningObject) +317

System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnectionBase
owningConnection) +90
System.Data.ProviderBase.DbConnectionClosed.Open(DbConnectionBase
outerConnection) +189
System.Data.ProviderBase.DbConnectionBase.Open() +62
System.Data.SqlClient.SqlConnection.Open() +168
ASP.Default_aspx.Page_Load(Object sender, EventArgs e) in
f:\study2\site\Default.aspx:13
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o,
Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender,
EventArgs e) +36
System.Web.UI.Control.OnLoad(EventArgs e) +102
System.Web.UI.Control.LoadRecursive() +45
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +952


Version Information: Microsoft .NET Framework Version:2.0.40607.16; ASP.NET
Version:2.0.40607.16

===

I use integrated security for SQL Server Express, database nn exists. OS:
Windows Server 2003. I also ran the following set of commands to grant access
to SQL Server from ASP.NET:

sp_grantlogin 'NT AUTHORITY\NETWORK SERVICE'
sp_grantdbaccess 'NT AUTHORITY\NETWORK SERVICE', 'NS'
grant all privileges on countries to NS

However, I'm able work with database in ASP.NET pages with the wizard-like
tools of Visual Web Developer.

I've tried several types of connection strings, searched through the
documentation but was unable to find a solution. Please help.
 
G

Guest

This is not the 2.0 group. It would be better to hook in there for other
questions. Here is the answer.

Under the SQL Server group in your start menu, there is a SQL Connection
tool. Open it and add TCP/IP (you can also potentially go with named pipes,
as that is your error message). Next, open services and stop and restart SQL
Express 2005. Finally, turn on the SQL Browser service. That should get you
up and running.


---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************

kostyantyn_salimov said:
I've the following simple page:

===

<%@ Page Language="C#" Debug="true" %>

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

<html>

<script language="C#" runat="server">
void Page_Load(Object sender, EventArgs e)
{

SqlConnection myConnection = new
SqlConnection("server=localhost;database=nn;Trusted_Connection=Yes");
myConnection.Open();
}
</script>

</html>

===

When I try to Start the page I got the following error:

===
Server Error in '/' Application.
Named Pipes Provider: The system cannot find the file specified.
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: Named Pipes Provider:
The system cannot find the file specified.

Source Error:
Line 11:
Line 12: SqlConnection myConnection = new
SqlConnection("server=localhost;database=nn;Trusted_Connection=Yes");
Line 13: myConnection.Open();
Line 14: }
Line 15: </script>

Source File: f:\study2\site\Default.aspx Line: 13

Stack Trace:
[SqlException (0x80131904): Named Pipes Provider: The system cannot find the
file specified.
]
System.Data.ProviderBase.DbConnectionPool.GetConnection(Object
owningObject) +317

System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnectionBase
owningConnection) +90
System.Data.ProviderBase.DbConnectionClosed.Open(DbConnectionBase
outerConnection) +189
System.Data.ProviderBase.DbConnectionBase.Open() +62
System.Data.SqlClient.SqlConnection.Open() +168
ASP.Default_aspx.Page_Load(Object sender, EventArgs e) in
f:\study2\site\Default.aspx:13
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o,
Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender,
EventArgs e) +36
System.Web.UI.Control.OnLoad(EventArgs e) +102
System.Web.UI.Control.LoadRecursive() +45
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +952


Version Information: Microsoft .NET Framework Version:2.0.40607.16; ASP.NET
Version:2.0.40607.16

===

I use integrated security for SQL Server Express, database nn exists. OS:
Windows Server 2003. I also ran the following set of commands to grant access
to SQL Server from ASP.NET:

sp_grantlogin 'NT AUTHORITY\NETWORK SERVICE'
sp_grantdbaccess 'NT AUTHORITY\NETWORK SERVICE', 'NS'
grant all privileges on countries to NS

However, I'm able work with database in ASP.NET pages with the wizard-like
tools of Visual Web Developer.

I've tried several types of connection strings, searched through the
documentation but was unable to find a solution. Please help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top