5 Replies - 1256 Views - Last Post: 02 October 2012 - 11:14 PM Rate Topic: -----

#1 triplesowcow  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 21
  • Joined: 31-August 11

How to connect to remote MSSQL server?

Posted 02 October 2012 - 06:37 PM

My connection string looks like:
SqlConnection myConnection = new SqlConnection("user id=NotRealID;" +
                       "password=NotRealPassword;server=MYPCNAME\\TESTSQLSERVER;" +
                       "Trusted_Connection=yes;" +
                       "database=TestDB; " +
                       "connection timeout=30");


And running the program on the same PC as the server, I can use myConnection.Open(); and a reader to retrieve data from my tables. When I run the program on a different computer I get an error saying the server is not found or inaccessible.

What do I change in the connection string to let me connect?

PS I followed the tutorials and set my server browser service to enabled named pipes as well as TCP/IP enabled and made sure the service was running.

Is This A Good Question/Topic? 0
  • +

Replies To: How to connect to remote MSSQL server?

#2 November-06  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 391
  • Joined: 04-January 11

Re: How to connect to remote MSSQL server?

Posted 02 October 2012 - 06:58 PM

It is a good practice to write your connectionstring in App.config for Windows Form or Web.config for Web Application.

Add the following codes in configuration

<connectionStrings>
   <add name="SampleName" connectionString="Data Source=YourServerName;Initial Catalog=YourDatabaseName;User ID=YourUserID;Password=YourPassword;" providerName="System.Data.SqlClient"/>
</connectionStrings>



You have to import System.Configuration by adding
using System.Configuration;


above the page in your code behind

You can get the connectionstring by
ConfigurationManager.ConnectionStrings["SampleName"].ConnectionString



You may notice that the "SampleName" is the name for the connectionstring.
Was This Post Helpful? 0
  • +
  • -

#3 triplesowcow  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 21
  • Joined: 31-August 11

Re: How to connect to remote MSSQL server?

Posted 02 October 2012 - 08:11 PM

Ok, but where can i find what to write for the address or server line for my server?
on my computer it works with server=MYPCNAME\\TESTSQLSERVER; but that doesn't seem to work when the program is run from a different computer.
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3469
  • View blog
  • Posts: 10,698
  • Joined: 05-May 12

Re: How to connect to remote MSSQL server?

Posted 02 October 2012 - 08:37 PM

From the other computer, can you even 'ping MYPCNAME' or do a 'net view \\MYPCNAME'? Basically do you have local DNS running so that the name MYPCNAME can be resolved? If you don't have DNS, then you may have to use the IP address instead of MYPCNAME.
Was This Post Helpful? 0
  • +
  • -

#5 triplesowcow  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 21
  • Joined: 31-August 11

Re: How to connect to remote MSSQL server?

Posted 02 October 2012 - 10:11 PM

My name is max, if I ping Max-PC on the other computer, it successful sends 4 packets to my computer's internal IP. both computers are on the same network. I have not set up a DNS server at my house.
Was This Post Helpful? 0
  • +
  • -

#6 triplesowcow  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 21
  • Joined: 31-August 11

Re: How to connect to remote MSSQL server?

Posted 02 October 2012 - 11:14 PM

Solved I put in the wrong port number in the firewall incoming rule. :stupid:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1