2

If I open some DB connection in some global viable in one call of the web service's method and if concurrently at second call of this method will it see this instance in this global viable ? Are this resources shared or each call has it's own resources ?

Thanks

3 Answers 3

3

Global variables tend to be just that, global. If your global variable is a C# static, it will be shared by webservice methods in the AppDomain. This is obviously error-prone - It is better, if each webservice method obtains a new connection when needed, and close it before the method finishes.

Sign up to request clarification or add additional context in comments.

4 Comments

My web methods are using some DAL Layer that not supports Concurrency. Because of that I am trying to understand what side effects I will see .
@Night Walker The biggest side effect it sounds like you can expect to see is a HUGE hit to performance. I'd suggest finding a new DAL.
@Night Walker, what does the DAL do with the connection ? Is the connection in fact stored in a static ? Does it have rules for opening/closing connections, etc. Depending on that, you may or might not have a severe concurrency problem. If you add some more info to your question, I will do my best to elaborate.
the connection is not closed , we have readers and writers and then we close them, but not the connection .
1

Usually Web service use Http request. In this case it's possible that each call you have to define the object, because the service are stateless...

Comments

1

For services it is better to use some kind of database connection management. Usually you can adapt Open/Close new connection on per-request basis. Note, most likely you will be working with logical connections and connection pool. Those are helpful to significantly reduce load to open physical connection. Physical connection is created without your direct control and is really heavy weight operation.

Do not put connection in a shared static variable, because connection is typically a disposable resource, which means you must dispose it. If something goes wrong and your connection to the database is corrupted then all your subsequent calls are deemed in doom.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.