Problem with making database connection...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • john20
    New Member
    • Jul 2008
    • 37

    #1

    Problem with making database connection...

    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.Sql Client.SqlExcep tion: 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(C onnectionString );
    Line 20: cnn.Open();
    Line 21: SqlCommand cmd = new SqlCommand();
    Line 22: cmd.CommandType = CommandType.Tex t;


    My Code is this :
    [code=cpp]
    string ConnectionStrin g = ConfigurationMa nager.AppSettin gs["ConnectionStri ng"];SqlConnection cnn = new SqlConnection(C onnectionString );
    cnn.Open();

    SqlCommand cmd = new SqlCommand();

    cmd.CommandType = CommandType.Tex t;
    cmd.Connection = cnn;

    DataSet ds = new DataSet();
    cmd.CommandText = "select Title from HumanResources. Employee";

    SqlDataReader reader = cmd.ExecuteRead er();
    [/code]
    and in the webconfig File i have the ConnectionStrin g like this:
    [code=xml]
    <appSettings>
    <add key="Connection String" value="server=B BMATRIXONE\SQLS ERVER2005NEW;Da tabase=Adventur eWorks;UID=sa;P WD=*******;pool ing=true"/>

    </appSettings>
    [/code]
    How to solve this error, please help me.

    Thanks

    -john
    Last edited by Frinavale; Oct 9 '08, 01:11 PM. Reason: added [code] tags
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

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

    Comment

    Working...