• Register
0 votes
257 views

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

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).

Conclusion:

· 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 15 views
15 views
The connection's current state is Connecting. When attempting to connect to the MSSQL database via ASP.NET online.
asked Aug 29 Sofi55 1.1k points
0 votes
1 answer 28 views
28 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 mphil 2.3k points
0 votes
1 answer 48 views
48 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
2 answers 206 views
206 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