Hey guys,

I have an application that connects to DB that is on a remote PC.
Problem is after a couple of minutes or so, it starts throwing exception.

1. The specified network name is no longer available.
2. Connection was forcibly closed by remote host.
3. connection was closed by software on the remote machine.

I couldn't find any solution for these problems.
Please help me with this one.

Thanks and regards

Are you using the connection the entire time?
What is the database connection timeout set to on both the client and the server?
What code are you using to access the database?
Do you check the connection to see if it is open before you use it?


Yes. I am using connection entire time.
I am trying to connect to sql server 2005.
Here's the code i am using to connect to the database.

                string strr = "Server=server name;Data Source=xxx.xxx.x.x;Network Library=DBMSSOCN;Initial Catalog=MIS;Connect Timeout=10000;User ID=sa;Password=";
                SqlConnection con1 = new SqlConnection(strr);

                if (con1.State.Equals(ConnectionState.Open))
                    MessageBox.Show("Connection Established");
            catch (Exception)
                MessageBox.Show("Could not establish connection to server");

remove connect time out from your connection string and then try to do your work

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.