Trouble connecting app to remote sql server

Posted on 2008-11-03
Last Modified: 2013-11-26
I have an app written in vs2008 using I'm attempting to connect to a sql server 2005 DB that's on another machine. All's well when I connect to the server on the development machine.

In the tcp/ip property pages, there are ip addresses given for IP1 and IP2, but they are different from the machine IP address.  which one should be in the connection string,  

and does someone have an example of a connection to connect to a remote sql server, so far, among the many I've tried are:

' Dim builder As New SqlConnectionStringBuilder
' With builder
'.DataSource = "\Server\Name"                                                     'Error 26

'.DataSource = "\Server"                                                        'Error 26

' .DataSource = "tcp:\\" ' TCP Provider, error: 0 - No connection could be made because the target machine actively refused it.)"

'.DataSource = "tcp:\\\Server\Name"                                                  ' TCP Provider, error: 0 - No connection could be made because the target machine actively refused it.)"

'.DataSource = "np:" ' provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"

'.DataSource = "np:\\.\pipe\MSSQL$HCSERVER\Sql\query" ' error: 26 - Error Locating Server/Instance Specified)"

'.DataSource = "lpc:" 'error: 41 - Cannot open a Shared Memory connection to a remote SQL server)"

'.DataSource = "lpc:\SAMSSQL\HCSERVER" error: 41 - Cannot open a Shared Memory connection to a remote SQL server)"

'.DataSource = "lpc:\SAMSSQL" error: 41 - Cannot open a Shared Memory connection to a remote SQL server)"

'.DataSource = "np:\\\\.\pipe\MSSQL$SAMSSQL\HCSERVER\Sql\query" ' Named Pipes Provider, error: 5 - Invalid parameter(s) found)"

'.DataSource = "np:\\" ' error: 25 - Connection string is not valid)"

'.DataSource = "tcp:\\" ' error: 25 - Connection string is not valid)"

'.DataSource = "tcp:\\\SAMSSQL\HCSERVER" 'error: 25 - Connection string is not valid)"

also I set
IntegratedSecurity = True
InitialCatalog = "Name"
UserID = "UID"
Password = "Password"'

and at times have used AttachDBFileName = "path of the file"

Any thought on why I'm having so much problems connecting?

Thanks in advance.

Question by:jbh_blue
    LVL 13

    Expert Comment

    You can get the connection string here

    You can also use SQLConnectionStringBuilder class to create the connection string
    LVL 83

    Expert Comment

    1) You are setting the integrated security to true as well as supplying user name and password.
    2) Why do you need to supply the protocols and ip address? "Data Source=TheDeveloper" should suffice for default instance and "Data Source=TheDeveloper\SQLEXPRESS" should be used for a named instance with name being SQLEXPRESS.
    3) Do you have the client protocols enabled in the SQL Server network configuration wizard?
    4) Do you have remote connections enabled in the SQL Server Surface Area Configuration?
    5) Do you have the SQLBrowser service enabled and running on the SQL Server?

    Author Comment

    1) I've removed  the integrated security setting.

    2) I got the advice about using the ip address from another poster, but it doesn't seem to make any difference.

    3) I'm not sure what this is but am looking for it. It's not on my menu options.

    4) Yes, I have Shared Memory, Named Pipes, and TCP/IP enabled.

    5) Yes

    I removed the integrated security property, and added the server name and instance as DataSource and was able to connect successfully, (or at least it seems)
    LVL 83

    Accepted Solution

    My suggestion helped you and you still are closing the question without giving any points?

    Author Comment

    TechTiger007 and CodeCruiser, thank you both very much.


    Author Comment

    Code Cruiser, I gave you points.

    Author Closing Comment


    Dude, I gave you points (350) and (150) to Tech Tiger, for him helping me with and the stringbuilder.

    I'm new to this site and if somehow I screwed up and you didn't get your points, let me know and tell me who to contact and I'll do my best to make sure you get your credit. But I specifically was given a screen on how to split the points between you two.

    Again,  Many thanks,

    LVL 83

    Expert Comment

    Its alright now. I just received the points now.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now