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.

12
  • Do you have SQLExpress server started locally? Commented Jul 31, 2017 at 14:47
  • have you searched on net for connection strings in sql server before posting the question Commented Jul 31, 2017 at 14:48
  • SQLExpress is a named instance. localhost is not going to work. Please read: stackoverflow.com/questions/3586196/… Commented Jul 31, 2017 at 14:54
  • Possible duplicate of Default instance name of SQL Server Express Commented Jul 31, 2017 at 14:54
  • Yes for both. I have been trying four different strings and started SQLExpress as administrator. And I am in that for three days. Commented Jul 31, 2017 at 14:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.