Connecting Tech Pros Worldwide Help | Site Map

Problem with making database connection...

Newbie
 
Join Date: Jul 2008
Posts: 28
#1: Oct 9 '08
Hi All,

I have recently installed Sql server 2005 on my machine and i am trying to connect to database for retreiving table information.

but it is giving me below error :

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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance 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: 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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

Source Error:

Line 18:
Line 19: SqlConnection cnn = new SqlConnection(ConnectionString);
Line 20: cnn.Open();
Line 21: SqlCommand cmd = new SqlCommand();
Line 22: cmd.CommandType = CommandType.Text;


My Code is this :
Expand|Select|Wrap|Line Numbers
  1. string ConnectionString = ConfigurationManager.AppSettings["ConnectionString"];SqlConnection cnn = new SqlConnection(ConnectionString); 
  2. cnn.Open(); 
  3.  
  4. SqlCommand cmd = new SqlCommand();
  5.  
  6. cmd.CommandType = CommandType.Text; 
  7. cmd.Connection = cnn;
  8.  
  9. DataSet ds = new DataSet(); 
  10. cmd.CommandText = "select Title from HumanResources.Employee";
  11.  
  12. SqlDataReader reader = cmd.ExecuteReader();
  13.  
and in the webconfig File i have the ConnectionString like this:
Expand|Select|Wrap|Line Numbers
  1. <appSettings> 
  2. <add key="ConnectionString" value="server=BBMATRIXONE\SQLSERVER2005NEW;Database=AdventureWorks;UID=sa;PWD=*******;pooling=true"/>
  3.  
  4. </appSettings>
  5.  
How to solve this error, please help me.

Thanks

-john
kenobewan's Avatar
Moderator
 
Join Date: Dec 2006
Posts: 4,745
#2: Oct 9 '08

re: Problem with making database connection...


This kb article may help you:
How to configure SQL Server 2005 to allow remote connections
Reply