Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9024045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:54:38+00:00 2026-06-16T05:54:38+00:00

First off I’d like to let everyone know I have searched my particular problem

  • 0

First off I’d like to let everyone know I have searched my particular problem and can’t seem to find what’s causing my problem.

I have an SQL Server 2008 instance running on a network machine and a client I have written connecting to it.

To connect I have a small segment of code that establishes a connection to an sql server 2008 instance and returns a DataTable populated with the results of whatever query I run against the server, all pretty standard stuff really. Anyway the issue is, whenever I open my program and call this method, upon the first call to my method, regardless as to what I’ve set my Connection Timeout value as in the connection string, it takes about 15 seconds and then times out. Bizarrely though the second or third call I make to the method will work without a problem.

I have opened up the ports for SQL Server on the server machine as outlined in this article: How to Open firewall ports for SQL Server and verified that it is correctly configured. Can anyone see a particular problem in my code?

    string _connectionString = "Server=" + @Properties.Settings.Default.sqlServer + "; Initial Catalog=" + @Properties.Settings.Default.sqlInitialCatalog +
        ";User Id=" + @Properties.Settings.Default.sqlUsername + ";Password=" + @Properties.Settings.Default.sqlPassword + "; Connection Timeout=1";

    private DataTable ExecuteSqlStatement(string command)
    {
        using (SqlConnection conn = new SqlConnection(_connectionString))
        {
            try
            {
                conn.Open();
                using (SqlDataAdapter adaptor = new SqlDataAdapter(command, conn))
                {
                    DataTable table = new DataTable();
                    adaptor.Fill(table);
                    return table;
                }
            }
            catch (SqlException e)
            {
                throw e;
            }
        }
    }

The SqlException that is caught at my catch is : “Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.”

This occurs at the conn.Open(); line in the code snippet I have included. If anyone has any ideas that’d be great!

Addendum If I ping the server it’s <10ms response time. Additionally I’m getting the same behavior when using SQL Server Management studio (I’ve just tried this after writing this question as the thought just crossed my mind). I would presume that this has to be a network issue as opposed to a code issue as it also takes two attempts when using SQL Server Management studio. I realise I can implement an error check for connection failure and then re-attempt the connection (I should probably do this anyway) but this doesn’t seem particularly ‘clean’ to me as it doesn’t address the underlying problem. Does anyone here have any experience with this issue?

Edit
Although over a year later this question has been viewed over 4000 times, I’ve since discovered that although I /thought/ the firewall ports were opened, they actually weren’t. I’d incorrectly assumed that you need to open the firewall in Windows to the port number that SQL Server uses, in my case I set it to allow connections on TCP port 1433, the firewall caused issues when attempting to establish an initial connection.

I discovered that the correct way to set it up was to set Windows Firewall to allow the SQL Server Instance executable through. To do this you need Add a Program in Windows Firewall, browse to the folder your sql instance resides in such as C:\Program Files (x86)\Microsoft SQL Server\MSSQL10_50.SQLINSTANCE\MSSQL\Binn and then add the sqlservr.exe file to the firewall rules.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T05:54:40+00:00Added an answer on June 16, 2026 at 5:54 am

    You are setting the connection timeout value to 1 second. Drop it from connection string and try again.

    Or the problem could be with the SQL select you are using. Could it be taking a long time. If so, the 2nd and 3rd calls would retrieve the cached values and thus run much quicker.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

first off I can't seem to figure what the first parameter in the pushState
First off, my problem is quite similar to this one . I would like
First off, I know there are ways to make it so that text can
First off, I only have a very basic understanding of SQL. I can create
First off, I know that you guys dislike it when questions like these are
first off I'm a noob to PHP but here is my problem. I am
First off, I would like to make clear, that I am SUPER NEW TO
First off, kudos to the amazing apache cordova team for making a platform-independent native-like
First off, I've never used GWT before. I have good experience in HTML/CSS/JS/JSP. I'm
First off, I'm using XCode 4.0.2. Okay, here is my issue. I can build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.