SQL Database Connectivity using C Sharp
- Hi,
I am using sqlserver 2005 as backend and Visual Studio 2008 as fontend in my application.
In the course of that, I need to do get some data from database( say employee table). I am using this code :
static
void Main(string[] args)
{
SqlConnection conn = new SqlConnection("Data Source = testserver;" + "Initial Catalog = employee;");
conn.Open();
SqlCommand command = conn.CreateCommand();
command.CommandText = "select * from Employee_Details";
SqlDataReader reader = command.ExecuteReader();
//display the result
while (reader.Read())
{
String output = reader["Employee name"].ToString();
Console.WriteLine(output);
}
reader.Close();
conn.Close();
}
but getting some problem :
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 am using windows authentication for sqlserver connection
and my Firewall service is not running.
I already chaeked, both named pipes & TCP/IP are enabled
SQL browser is running
Remote connection is also enabled.
But, may be I am missing somthing in the code...please help me...!- Moved byXiao-Min Tan – MSFTMSFT, ModeratorTuesday, November 10, 2009 3:42 AM (From:SQL Server Database Engine)
- Moved byJin ChenMSFTMonday, November 09, 2009 2:04 AMMove to appropriate forum. (From:SQL Server Reporting Services)
Answers
- Please make sure you have all this right as explained in :http://mssqlonline.blogspot.com/2009/05/sql-server-fix-error-provider-named.htmlCheersAnand
- Marked As Answer byNai-dong Jin - MSFTMSFT, ModeratorFriday, November 13, 2009 4:24 AM
All Replies
- Please make sure you have all this right as explained in :http://mssqlonline.blogspot.com/2009/05/sql-server-fix-error-provider-named.htmlCheersAnand
- Marked As Answer byNai-dong Jin - MSFTMSFT, ModeratorFriday, November 13, 2009 4:24 AM
- Hi,
Here's another article for you to refer.
http://support.microsoft.com/kb/914277
Thanks.
Microsoft Online Community Support Please remember to mark the replies as answers if they help and unmark them if they provide no help.


