1

I cant connect to the database with my PC IP Adress, but i can connect to the database with my PC Name. How i can fix it or i can configure it in sql server ?

So, what are the differences between PC Name and 127.0.0.1 to connect SQL Server ?

Here is different my code:

mssql_connect("MYPCNAME","sa","solution") or die('Connection Failed'); //this is OK

mssql_connect("127.0.0.1","sa","solution") or die('Connection Failed'); // this is failed

i need your expertise ;)

BMN
  • 8,253
  • 14
  • 48
  • 80
Acil Az
  • 170
  • 2
  • 9
  • WHat happens, what error messages do you get? Is `MYPCNAME` actually your local computer? – Pekka Jul 04 '12 at 10:06
  • Is apache and mysql servers turned on? Are you using xampp? – Nurlan Jul 04 '12 at 10:06
  • 1
    @NurlanKenzhebekov: Please read the question, the OP is using MSSQL, not MySQL. And Apache is completely unrelated to this issue. – ThiefMaster Jul 04 '12 at 10:08
  • Check your DNS configuration. Sounds like there will be a `resolv` error somewhere. – Whisperity Jul 04 '12 at 10:08
  • 1
    How exactly is DNS involved when using `127.0.0.1` For that IP even the reverse lookup usually does not use a DNS server. – ThiefMaster Jul 04 '12 at 10:10
  • Possibly related question: http://stackoverflow.com/questions/360141/how-to-connect-to-local-instance-of-sql-server-2008-express – ThiefMaster Jul 04 '12 at 10:12
  • @Pekka : Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: 127.0.0.1 in D:\xampp\htdocs\risets\mssql_conn.php on line 3 , and if i change the 127.0.0.1 with MYPCNAME( my computer name ) it can successfully connected. – Acil Az Jul 04 '12 at 10:16
  • @Nurland : my Apache was turned on, i don't need mysql so i turn it off... @ Whisperity : how i can find the configuration option ? – Acil Az Jul 04 '12 at 10:19

2 Answers2

2

It may work if you are using the port number, e.g.:

mssql_connect("127.0.0.1:1433","sa","solution") or die('Connection Failed'); 

If you are using PHP on Windows try:

 mssql_connect("127.0.0.1,1433","sa","solution") or die('Connection Failed'); 
Stephan Weinhold
  • 1,623
  • 1
  • 28
  • 37
Krishna
  • 353
  • 2
  • 15
  • i was try that and coonfigure in windows firewall to open the port, but still can't connect.. :( – Acil Az Jul 04 '12 at 10:23
  • you can try mssql_connect("127.0.0.1:1433\\database","sa","solution") or die('Connection Failed'); or see my above answer(edited) – Krishna Jul 04 '12 at 10:27
  • i still can't connect to other PC... is there have an configuration on the other PC that i want to connect ? – Acil Az Jul 05 '12 at 03:39
0

When using a hostname it usually resolves to the non-loopback address of the machine. Using localhost or 127.0.0.1 will always use the loopback interface.

Most likely SQL Server does not bind to the loopback interface but only to the real interface (the one with the IP you get when resolving MYPCNAME). You could either keep using a PC Name or its IP or configure SQL Server to listen on the loopback interface, too.

ThiefMaster
  • 310,957
  • 84
  • 592
  • 636