none
error connecting to sql2005, im a beginner RRS feed

  • Question

  • im new the field and i had this proplem connecting to the database

    here is the code :

     

    string connectionString = "server = ., database = adventureworks, uid = sa, pwd = pwd";

    SqlConnection connection = new SqlConnection(connectionString);

    connection.Open();

    connection.Close();

     

    here is the 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: 25 - Connection string is not valid)

     

    - i use sqlserver 2005

    - i use visual studio 2005

    - the sql browser is running

    - the protocls enabled are: TCPIP | Named Pipes

    - the sql server, & client app is on my computer

    - i cant ping my computer

    what i mean is "C:\ping machine name" doesn't work

    - i tried this also "telnet 127.0.0.1 1433" and it doesn't work

     

    Thursday, August 9, 2007 6:43 PM

Answers

  • I believe you need to use semicolon between the properties in your connection string. Plus it is possible you need to specify instance name for your SQL Server if it was installed as instance or in a case if it is local SQL Server 2005 Express. Your connection string would look like

     

    "Server=.\INSTANCENAMEHERE; Database=AdventureWorks;UID=sa;pwd=pwd"

     

    or, for the SQL Server express

     

    "Server=.\SQLEXPRESS; Database=AdventureWorks;UID=sa;pwd=pwd"

     

    Friday, August 10, 2007 10:39 AM
    Moderator

All replies

  • Here's a sample connection string for connecting to Sql Server 2005:

    Code Snippet

    string _connectionString = "Data Source=Main;Initial Catalog=AdventureWorks;User Id=username;Password=password;";



    Sean
    Thursday, August 9, 2007 11:54 PM
  • I believe you need to use semicolon between the properties in your connection string. Plus it is possible you need to specify instance name for your SQL Server if it was installed as instance or in a case if it is local SQL Server 2005 Express. Your connection string would look like

     

    "Server=.\INSTANCENAMEHERE; Database=AdventureWorks;UID=sa;pwd=pwd"

     

    or, for the SQL Server express

     

    "Server=.\SQLEXPRESS; Database=AdventureWorks;UID=sa;pwd=pwd"

     

    Friday, August 10, 2007 10:39 AM
    Moderator
  • that was helpful, thank you VMazur

    Friday, August 10, 2007 11:44 AM