0

I am tried to connect to a database server with tcp port and public ip, but at time to open connection get next error: "Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding." The windows server have port open in firewall and this port is added in SQL Configuration Manager > TCP/IP > IP Addresses > IP ALL TCP PORT. I hope that you can help me. Thanks.

The C# code is:

public DataTable FillDataTable(string table)
    {
        string query = "SELECT * FROM " + table + ";";
        string conSTR = @"Data Source=tcp:xxx.xxx.xxx.xxx,xxxx; Initial Catalog=WorkFlow; 
            User id=admin; Password=admin01;";
        DataTable dt = new DataTable();

        try
        {
            using (SqlConnection sqlConn = new SqlConnection(conSTR))
            using (SqlCommand cmd = new SqlCommand(query, sqlConn))
            {
                cmd.CommandTimeout = 30;
                sqlConn.Open();                   
                dt.Load(cmd.ExecuteReader());
            }
        }
        catch (Exception exc)
        {
            string msg = exc.Message.ToString();
        }

        return dt;
    }
  • have you read up on how to configure your database to connect using `TCIP/NamePipes` do you have a qualified / experienced DBA in your location..? have you executed a google search on how to connect to Sql Server via tcp or configure a connection string using TCP..? also read up on how to use the `Fill()` method when executing a Select Statement ..you call your method `FillDataTable` but do not use the `Fill()` method is kind of odd.Checkout @Freelancer answer here [DataTable Fill()](https://stackoverflow.com/questions/16958155/fill-datatable-from-sql-server-database) – MethodMan Nov 20 '17 at 19:39
  • @MethodMan I searched this theme, i found how to configure, i forgot, my server is connected through a modem, the modem is from third parts, I should to configurate the modem for allow connections from another ip? – Reynaldo Granados Nov 20 '17 at 20:08
  • Can you connect using Sql Server management studio using these connection details? – SE1986 Nov 20 '17 at 20:11

0 Answers0