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.
asked
Jan 23 '12 at 03:08 AM
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...
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.