• Register
0 votes

Problem :

When I am attempting to connect to MSSQL database via ASP.NET online, I will often get the below error when two or more people try to connect simultaneously:

ExecuteReader requires an open and available Connection. The connection's current state is Connecting.

My site works fine on the localhost server.

May I know what might have gone wrong with my site and how can I fix the error?

7 5 2
3,870 points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

If you are even using the static connections you're trying to create the lock for every thread trying to access your object. ASP.NET is the multithreading environment by its nature. So there is the great chance for these locks which causes the performance issues at best. Actually very soon or later you will start geting many different exceptions(like the ExecuteReader requires an open and available Connection etc).


· Don't reuse the connections or any of the ADO.NET objects at all.

· Don't make them the static or shared(in VB.NET)

· Always try to create, open(in case of the Connections), use the close and dispose them where you need them(example  in the method)

· Use a using-statement to dispose and close(in case of  the Connections)  implicitly

That is very true not only for your Connections. Every object implementing the IDisposable should be disposed(simplest by the using-statement), all and more in a System.Data.SqlClient namespace.

All the above tries to speaks against the custom DB-Class which encapsulates and reuse the all objects.

9 7 4
38,600 points

Related questions

0 votes
1 answer 70 views
The connection's current state is Connecting. When attempting to connect to the MSSQL database via ASP.NET online.
asked Aug 29, 2020 Sofi55 1.1k points
0 votes
1 answer 87 views
Problem : I am beginner in C#. I am trying to write the Function using C#. But while executing my code I am facing below error “The connection was not closed. The connection's current state is open.” How to fix above error?
asked Feb 27, 2020 mphil 2.3k points
0 votes
1 answer 4 views
Problem: I have a C# Application I am creating that stores all data in SQL Server. Sometimes it's easier for me to make data changes programmatically and sometimes it's easier to have stored procedures and functions in the SQL Server database and call them. I am rather new to ... This is a solo project, so I can refactor any amount of code I want to make it better. All options are on the table.
asked Apr 25 sumaiya simi 43.9k points
0 votes
1 answer 4 views
Problem: I am using Paging to show data in datagridview, but when I try to Update any data with updatebutton data should be updated In datagridview as well as in the database. But I get this error: Update requires a valid UpdateCommand when passed DataRow collection with modified rows
asked Apr 24 ummeshani 9.5k points
0 votes
1 answer 5 views
Problem: An ADO.Net application is only sometimes able to connect to another server on the local network, the error returned is: Connection Timeout Expired. The timeout period elapsed while attempting to consume the pre-login handshake acknowledgement.
asked Apr 22 ummeshani 9.5k points
0 votes
1 answer 1 view
1 view
Problem: Can anyone tell me the solution of this problem?Which of the following is not the method of dataadapter
asked 21 hours ago Ifra 36.4k points
0 votes
1 answer 2 views
Problem: Is there any way to solve this? > Executereader: connection property has not been initialized.
asked 5 hours ago Irenka Kiri 4.9k points
0 votes
1 answer 74 views
Problem : I am having my radcombo machines on aspx page and whenever I try to select any option from them then it gives me following `Server Error in '/' Application. Exception Details: System.InvalidOperationException: Operation is not valid due to the current state of the object. My Version Information: Microsoft .NET Framework Version: 2.0.50727.3634 ASP.NET Version: 2.0.50727.3634
asked Dec 2, 2019 alecxe 7.5k points
0 votes
1 answer 9 views
Problem: I need someone to understand this problem and find out the solution… unable to find the requested .net framework data provider
asked Mar 25 Ifra 36.4k points
0 votes
1 answer 7 views
Problem: Can anyone tell me the solution of this problem? an existing connection was forcibly closed by remote host
asked Apr 3 Ifra 36.4k points