Search Unity

No connection could be made because the target machine actively refused it.

Discussion in 'Multiplayer' started by ultraviol3nt, Jul 20, 2013.

  1. ultraviol3nt

    ultraviol3nt

    Joined:
    Jan 17, 2010
    Posts:
    155
    So trying to get a connection from my game to the database on my server, and Unity complains with this error message:

    Code (csharp):
    1. SocketException: No connection could be made because the target machine actively refused it.
    2.  
    I thought at first maybe I gave it the wrong username and password, but that's not the case. Code:

    Code (csharp):
    1. import System;
    2. import System.Data;
    3. import System.Data.SqlClient;
    4.  
    5. var DBi : String;
    6. var DBs: String;
    7. var DBu: String;
    8. var DBp: String;
    9.  
    10. function Start () {
    11.     var dbcon : IDbConnection;
    12.     var connectionString : String = "Server=****; Database=****; Uid=****; Pwd=****";
    13.     dbcon = new SqlConnection(connectionString);
    14.     dbcon.Open();
    15. }
    Anyone know what I've done wrong? Or if the problem is even on Unity's side?
     
  2. eskimojoe

    eskimojoe

    Joined:
    Jun 4, 2012
    Posts:
    1,440
    Did you open the port / or allow Unity3D or allow your game to receive connections in Windows Firewall?
     
  3. ultraviol3nt

    ultraviol3nt

    Joined:
    Jan 17, 2010
    Posts:
    155
    I did. 3306. But they're both on the same network, so that shouldn't matter.
     
  4. eskimojoe

    eskimojoe

    Joined:
    Jun 4, 2012
    Posts:
    1,440

    Try disable the firewall.


    Does it work?
    If not -> Something wrong with the codes.
     
  5. ultraviol3nt

    ultraviol3nt

    Joined:
    Jan 17, 2010
    Posts:
    155
    Firewall's already disabled. Also, is no one seeing the significance of the wording "actively refused it"? This means the server was connected to, but the server itself said no. It's not a failed connection in the normal sense, it's a disallowed connection. Besides, I was following the instructions in this thread almost verbatim...
     
    mcbauer likes this.
  6. ultraviol3nt

    ultraviol3nt

    Joined:
    Jan 17, 2010
    Posts:
    155
    I'm seriously at the end of my line here... I honestly have no idea what to do, I've tried everything. I've tried two different MySQL clients on my iPhone, and they can both connect, and a friend of mine made a PHP connect script that worked.. I am at a complete loss..
     
  7. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,066
    If you accidentally build with WebPlayer settings, the player will fire a policy request which might fail.
    Is the db address you enter available from the machine? You said you tested with iPhone and some PHP. It's unclear if the connection from the Unity machine will do. If it's in another local net, it might not connect while others do.
     
  8. ultraviol3nt

    ultraviol3nt

    Joined:
    Jan 17, 2010
    Posts:
    155
    I've gotten a friend who's working on his own project to test the code. He has no luck either, and he's very decidedly outside of the network. It seems like everything BUT Unity is able to connect...

    I've updated the code as well, so as to make it ready when it actually.. you know... WORKS...

    Code (csharp):
    1. import System;
    2. import System.Data;
    3. import System.Data.SqlClient;
    4.  
    5. static var DBi : String = "";
    6. static var DBu: String = "";
    7. static var DBp: String = "";
    8.  
    9. function Start () {
    10.     QueryDB("", "");
    11. }
    12.  
    13. static function QueryDB
    14. (dbSchema : String, dbQueryString : String) {
    15.     var dbConnection : IDbConnection;
    16.     var dbConnectionString : String =
    17.     "Server=" + DBi + ";" +
    18.     "Database=" + dbSchema + ";" +
    19.     "Uid=" + DBu + ";" +
    20.     "Pwd=" + DBp;
    21.     dbConnection = new SqlConnection(dbConnectionString);
    22.     dbConnection.Open();
    23. }
     
  9. eskimojoe

    eskimojoe

    Joined:
    Jun 4, 2012
    Posts:
    1,440
    You are confusing two things. MySQL and MSSQL.


    The person who made the demo used MSSQL. You are using MySQL.
     
  10. ultraviol3nt

    ultraviol3nt

    Joined:
    Jan 17, 2010
    Posts:
    155
    is that all it was?

    Are you srs?

    Are you bloody kidding me?

    I've been chasing this for three days

    excuse me while i go question every decision i've ever made.

    Every. Decision.

    I've.

    Ever.

    Made.
     
    Last edited: Jul 23, 2013
    BryanO likes this.
  11. eskimojoe

    eskimojoe

    Joined:
    Jun 4, 2012
    Posts:
    1,440
    Hi,
    (REMOVED)


    The uLink vendor is around, did you try uLink and connect to MySQL?

    The Photon vendor is around, did you try Photon Server and connect to MySQL?
     
    Last edited: Jul 23, 2013
  12. eskimojoe

    eskimojoe

    Joined:
    Jun 4, 2012
    Posts:
    1,440

    You also need to question why you need to have a MySQL client on the iPhone too.


    Usually:

    1. game access server software,
    2. the server software accesses the MySQL to update, delete, create records.

    Not:

    1. PC game accesses MySQL client directly from remote clients
    2. Android game accesses MySQL client directly from remote clients
    3. iPhone game accesses MySQL client directly from remote clients


    If you leave your MySQL client open, it can be very easily hacked or defaced.
     
  13. ultraviol3nt

    ultraviol3nt

    Joined:
    Jan 17, 2010
    Posts:
    155
    The iPhone client was just to see if my database was even accessible or if the problem was with something I did, it has nothing to do with the project itself. Also, any code I posted was just making sure I could actually get in, I'll get it together once I figure out how to work with these libraries.
     
    Last edited: Jul 23, 2013
  14. ultraviol3nt

    ultraviol3nt

    Joined:
    Jan 17, 2010
    Posts:
    155
    I'm not even going to bother looking for those for a few reasons:

    1) I have no funds, and the typical trend here is that if any community-made plugins have a reputation (which these do), they're pretty expensive.
    2) I'm already going mental from trying to figure out how to use the NORMAL Unity networking system
    3) I'm sick of Unity in general, halfway regret buying the Pro license, and am considering just giving my current project the finger and going to a different engine, because I'm sick of the fact that I can get more features from engines that I don't even have to pay for.
     
  15. iamthecoolguy11

    iamthecoolguy11

    Joined:
    Jan 11, 2013
    Posts:
    8
    I had the same problem and its because unity is blocking it. In order to connect sometimes you need to put this before connecting to the server.
    1. void Connect()
    2. {
    3. //before connecting I need to tell unity to turn security off for the port im going to use
    4. Security.PrefetchSocketPolicy(IP,PORT);
    5. //now I can connect to the server with out any problems hopefully
    6. ClientSocket.Connect(IP,PORT);
    7. }
     
  16. mmpk

    mmpk

    Joined:
    Aug 11, 2017
    Posts:
    1
    I am facing same problem, but the remedy u mentioned Security.PrefetchSocketPolicy(IP,PORT), has been obsolete now. any other workaround
     
  17. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    The entire old webplayer is gone as of 5.40, so there's no way you're facing the same problem that iamthecoolguy11 worked around with the webplayer's Security class. Your issue must be due to a different problem.
     
  18. Deleted User

    Deleted User

    Guest

    I solved it this way:
    In Server Configuration Manager under your server protocols section make sure TCP/IP is enabled. Right click on TCP/IP and go to properties and check for IPAII dynamic port number. You need to mention this port in the connection string. For more details refer this page
    https://blogs.msdn.microsoft.com/sq...cause-the-target-machine-actively-refused-it/