0

I had a issue connecting Unity 5.5.3 to my database made with SQL Express. The error showed in Exception was:

System.Data.SqlClient.SqlException: Server does not exist or connection refused. ---> Mono.Data.Tds.Protocol.TdsInternalException: Server does not exist or connection refused. ---> System.Net.Sockets.SocketException: Address incompatible with protocol.

My code for connection is that:

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Data;
using System.Data.SqlClient;


public class connectivity : MonoBehaviour
{
    private string connectionstring;


// Use this for initialization
void Start()
{

    Debug.Log("Connecting to database...");
    connectionstring = "Server=localhost;" + 
                        "Database=Teste;" +
                        "User ID=fernando;" +
                        "Password=fernando123;";



    SqlConnection dbConnection = new SqlConnection(connectionstring);


    try
    {

        dbConnection.Open();
        Debug.Log("Connected to database.");
    }
    catch (SqlException _exception)
    {
        Debug.LogWarning(_exception.ToString());

    }


    //  conn.Close();
}

// Update is called once per frame
void Update()
{

}
}

Does somebody knows why it can't recognize the Server? I already have add the connection with my server using Server Explorer Data Connections.

0 Answers0