• 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 48 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 59 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 61 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 3 views
Problem : cannot drop database because it is currently in use
asked 5 days ago Shovo210 3.1k points
0 votes
2 answers 357 views
Problem : Currently I am migrating from the Identity 1.0.0 to Identity 2.0.1. But the migrations code generated is nothing about the new IdentityUser. And It does not even add the new columns. So I tried to make the new project and also I ... current context At below line IdentityResult result = await UserManager.CreateAsync(user, model.Password); Any clue about the solution on my above problem?
asked Dec 25, 2019 alecxe 7.5k points
0 votes
1 answer 18 views
How can I connect to Db2 databse. My Client has AS/400 iSeries database. I am trying to access the database from c# application.
asked Sep 16, 2020 Oscar909 460 points
0 votes
1 answer 83 views
Problem : My Query is giving the strange error as follows there is already an open datareader associated with this command which must be closed first.
asked Nov 15, 2019 peterlaw 6.9k points
0 votes
1 answer 24 views
0 votes
1 answer 109 views
Problem : After compiling my C# code I am getting below error: error: An unhandled exception of type 'System.Net.WebException' occurred in System.dll Additional information: The underlying connection was closed: An unexpected error occurred on a receive. At the line HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse(); please let me know if anybody has solution on it.
asked Jan 18, 2020 jwilliam 3.9k points