Connecting Tech Pros Worldwide Forums | Help | Site Map

Server-Clients, Threads, Reflection, Processes and Everything Else

Newbie
 
Join Date: May 2008
Posts: 11
#1: Nov 20 '08
Hi All

I've got a real puzzler that I just can't seem to get my head around. Basically I'm writing a server-client using a third party dll to access their database. The third party library requires a login using a static method before any of the other methods can be used:

tpdll.Login(Username, Password); *

* The username and password will always be the same in my app

When a client connects to my server app it fires a new thread and calls this login. If there is only 1 client connecting at a time its fine. If one client connects and then a second client connects while the first is still logged into the third party dll the first client is disconnected from using the dll.

I've tried 2 completely seperate applications that log into the third party dll using the same logins and run them parallel and they worked fine so I know the third party app allows the same user to be logged in twice. So is this a problem with the threads using the same login at the same time? If so is there anyway to load the dlls seperately for each thread?

I'm using c# .net 2.0

balabaster's Avatar
Moderator
 
Join Date: Mar 2007
Location: Canada
Posts: 757
#2: Nov 20 '08

re: Server-Clients, Threads, Reflection, Processes and Everything Else


Sounds like a bug in their dll... have you tried contacting them? It seems to me that if it's a static method then it should be written such that it is threadsafe. Does the method return a value?
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,161
#3: Nov 20 '08

re: Server-Clients, Threads, Reflection, Processes and Everything Else


I would say what is happening is you have created what is really a single instance of the object, that is being shared over the webapplication (application only loads the dll once after all)
And you are trying to use it as if it were being loaded each time?

Try pretending like every user on the web application is the same and coding for that way (you might have to put in some lock(){} calls to prevent race conditions) and see if that stops one person being shut out by the other?
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,137
#4: Nov 20 '08

re: Server-Clients, Threads, Reflection, Processes and Everything Else


Quote:

Originally Posted by Plater

I would say what is happening is you have created what is really a single instance of the object, that is being shared over the webapplication (application only loads the dll once after all)
And you are trying to use it as if it were being loaded each time?

Try pretending like every user on the web application is the same and coding for that way (you might have to put in some lock(){} calls to prevent race conditions) and see if that stops one person being shut out by the other?


I think Plater's on to something here.

I did that once.

I was half following a tutorial when creating a DLL that handles database interactions.... the tutorial declared a shared database connection and I wasn't paying attention to the "Shared" keyword...

When I used it in a multi-threaded application and tried I ran into some pretty crazy problems with the DLL. Much like you are describing here.

-Frinny
Reply