x


SQL and Unity connection refused.

I've set up a local server and database using MySQL and have followed a tutorial in trying to access the database. So far I have the following code:

import System;
import System.Data;
import System.Data.SqlClient;

private var database : IDbConnection;
private var connectionString : String =
    "Server=localhost;" + 
    "Database=test;" +
    "User ID=demo;" +
    "Password=demo;";

function Start(){
    database = new SqlConnection(connectionString);
    database.Open();
    var dbcmd : IDbCommand = database.CreateCommand();
    var cmdSql : String = "SELECT * FROM unityDemo;";
    dbcmd.CommandText = cmdSql;
    var reader : IDataReader = dbcmd.ExecuteReader();

    while(reader.Read()) {
       var name : String = reader ["Name"].ToString();
       var comment : String = reader ["Comment"].ToString();

       print ("Name: " + name + "Comment: " + comment);
    }

    reader.Close();
    reader = null;
    database.Close();
    database = null;
}

However when I run it I get the following error message:

SocketException: Connection refused System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP, Boolean requireSocketPolicy) System.Net.Sockets.Socket+Worker.Connect () Rethrow as TdsInternalException: Server does not exist or connection refused.

Can anyone spot why I can not connect to the database? Any advice would greatly help.

more ▼

asked Jan 23 '12 at 03:08 AM

unity200 gravatar image

unity200
16 9 10 12

hmm y not use a php server and call it using www class??! it jus worked for me w/o any probs...

Jan 23 '12 at 05:14 AM flamy

I have more familiarity with MySQL. I'm sure it will be something simple but extensive internet look ups have not helped. I still can't figure out why my connection is refused.

Jan 23 '12 at 09:09 PM unity200
(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3717
x88
x62

asked: Jan 23 '12 at 03:08 AM

Seen: 753 times

Last Updated: Jan 23 '12 at 09:09 PM