"A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections.
(provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"
From SQL server management Studio, I can see the database is accessible and is opened. How come my conn.open was failed?
From SQL server management Studio you logged in as admin, but your ASP.NET application use the application pool user rights, so you should give the application pool user SQL server rights.
From SQL server management Studio you logged in as admin, but your ASP.NET application use the application pool user rights, so you should give the application pool user SQL server rights.
Regards
Hi, thanks a lot,
but in my web project, the other web page, I use entityframework, I do not need to set any access to the application pool, it connects well.
in this page, since I do not know to use entityframework, that is why I still use this way to connect, but it failed.
Could you show me how to give the application pool user SQL server rights? it seems I have never do this in my other web apps. thanks
From your connection string, you use windows authentication to connect your server1 instance. Please change your connection string like below and then try again.
From your connection string, you use windows authentication to connect your server1 instance. Please change your connection string like below and then try again.
Peter Cong
Member
527 Points
681 Posts
How come my SQL connection is failed?
Jan 05, 2013 06:14 PM|LINK
Hi, I am trying to connect my tables on SQL server, but I got this error:
string connStr = @"Data Source=Data Source=Server1;Initial Catalog=Testdb;Integrated Security=True"; System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(connStr);
conn.Open();//here gets the following message
"A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"
From SQL server management Studio, I can see the database is accessible and is opened. How come my conn.open was failed?
Anybody knows why? Thanks
HostingASPNe...
All-Star
15878 Points
2975 Posts
Re: How come my SQL connection is failed?
Jan 05, 2013 06:37 PM|LINK
Hello,
From SQL server management Studio you logged in as admin, but your ASP.NET application use the application pool user rights, so you should give the application pool user SQL server rights.
Regards
Free ASP.NET Examples and source code.
Peter Cong
Member
527 Points
681 Posts
Re: How come my SQL connection is failed?
Jan 05, 2013 08:20 PM|LINK
Hi, thanks a lot,
but in my web project, the other web page, I use entityframework, I do not need to set any access to the application pool, it connects well.
in this page, since I do not know to use entityframework, that is why I still use this way to connect, but it failed.
Could you show me how to give the application pool user SQL server rights? it seems I have never do this in my other web apps. thanks
oned_gk
All-Star
31507 Points
6429 Posts
Re: How come my SQL connection is failed?
Jan 05, 2013 10:15 PM|LINK
Chen Yu - MS...
All-Star
21584 Points
2493 Posts
Microsoft
Re: How come my SQL connection is failed?
Jan 07, 2013 02:44 AM|LINK
Hi,
From your connection string, you use windows authentication to connect your server1 instance. Please change your connection string like below and then try again.
string connStr = @"Data Source=Server1;Initial Catalog=Testdb;Integrated Security=True";
More information connection string: http://www.connectionstrings.com/sql-server-2008
Thanks.
Feedback to us
Develop and promote your apps in Windows Store
Peter Cong
Member
527 Points
681 Posts
Re: How come my SQL connection is failed?
Jan 07, 2013 03:15 AM|LINK
Thanks, it works, I can see I have typo in my codes, appreciate your help