SQL Server Performance

How to connect to SQL Server 2008 from remote machine and get the result?

Discussion in 'SQL Server 2008 General Developer Questions' started by btough, May 15, 2009.

  1. btough New Member

    I have created Windows Form application in VS2008 using C#. I have 'SQL Server 2008' installed on my machine. Now my application have code such that, I can connect to the 'SQL Server 2008', fire qury on it, get the result of the query.
    Now I want , 'SQL Server' will be on one machine say machine1 and my application is running on another machine say machine2. Now my application should connect to 'sqlserver' using IP address and get the result. So how can I connect the remote 'SQL Server' from my application?
    Any help will be appreciated.
  2. moh_hassan20 New Member

    modify the connection string, and set data source = ip address, example for integrated security
    string connectionString = “Data Source=;” + “integrated security=SSPI;” + “database=YourDatabase”;
    For test , try to coonect to the remote server using the wizard in vs2008 , and use the generated connection string
    be sure that user has access right to the database
  3. btough New Member

    Thank you.

    My connection String is like -
    "Data Source=Ip Address Of SQl Server machine,1433;Network Library=DBMSSOCN;Initial Catlog=myDatabaseName;Integrated Security=True;User Instance=True"

    From SQL Server Configuration Manager, TCP/IP is enabled.

    But it does not work. Am I missing something or doing something wrong?

    Thanks in advance.
  4. moh_hassan20 New Member

    do you connect with named instance or sql express.? you have to add it on the connection string e.g. /myinstance
    you may be connected using dynamic port , or other static port (1433 is default and need not be used in the connection string)
    check configuration manager on the server , network protocol for exact static port#
    run sql browser service in the server (needed in case of dynamic port)
    try this:
    "DataSource=Ip Address Of SQl Server machine;Initial Catlog=myDatabaseName;IntegratedSecurity=True;User Instance=True"

  5. btough New Member

    Thank you very much for reply.
    As I am new to SQL Server, I don't know how to run sql browser service in the server. Can you please make me clear on it?
    I checked the 'Sql Server Browser' from 'Sql Server Configuration Manager->Sql Server Services', it's State is Stopped.
    I tried with following connection string -"server=Sql Server Machine Ip Address:Sql Server Instance Name;Initial Catalog=myDataBase;Integrated Security=True;User Instance=True"
    I am getting the error as -
    " System.Data.SqlClent.SqlException : A network related or instance specific error occured 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 configered to allow remote connections. (Provider -Sql Network Interface, error : 25 - Connection String is not valid) ".
    What is wrong with the connection string?
    Thanks in advance.
  6. moh_hassan20 New Member

    the error is due to "Connection String is not valid"
    that syntax is not valid "Sql Server Machine Ip Address:Sql Server Instance Name"
    to avoid try and error , try to use the connection wizard in vs2008 to connect to the database on the remote server.
    it is easy and accurate , and will help you to resolve the syntax of connection string
    If connected , copy and past the connection string.
  7. btough New Member

    Hello moh_hassan20,
    Many thanks for help.

Share This Page