Skip to content
Advertisement

Error while connecting to SQL Server. The server was not found or was not accessible

I am trying to connect to my SQL Server database. I am using C#. Here is my code:

string connectionString = @"Server = tcp:<myLocalIP>, 1433; Initial catalog = <DatabaseName>;
        User Id = <User>; Password = <Passwd>;",
            queryString = "SELECT * FROM [...]";

        SqlConnection connection = new SqlConnection(connectionString);
        SqlCommand SelectCommand = new SqlCommand(queryString, connection);
        SqlDataReader myreader;
        connection.Open();

        myreader = SelectCommand.ExecuteReader();

        List<String> lst = new List<String>();
        while (myreader.Read())
        {
            lst .Add(myreader[0].ToString());

        }
        connection.Close();

But connection.Open() throws an error:

SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 0).

My server is started, it allows remote connections and TCP/IP is enabled. Any ideas?

Advertisement

Answer

I found a solution. I created a server(Console Application) that connects to MySQL server. Then I connected my Xamarin/ASP.NET application to that server where I process queries.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement