Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have this extremely simple procedure, and for some reason it works when I'm activating it using the Visual Studio's Database thingy, but fails when I'm using it from my code (the extracted value is 0 instead of 1 when there's such a user).

SQL
CREATE PROCEDURE Client_Authenticate
 (@ID int,@Password varchar(32),@OutAuthenticated tinyint OUTPUT) AS
 BEGIN
 	SELECT * FROM _Clients WHERE ClientID = @ID AND MD5Hash = @Password
	SET @OutAuthenticated = @@ROWCOUNT
 END


Also the following procedure seem to do nothing when executed from code.

SQL
CREATE PROCEDURE Client_ConnectionChanged
 (@ID int,@Value tinyint) AS
 BEGIN
 UPDATE _Clients SET ClientConnected = @Value WHERE ClientID = @ID
 END

Any reasons why it should fail?
Posted
Updated 29-Oct-11 10:14am
v2

1 solution

Visual Studio Database thingy? I'm unfamiliar with that tool :)

There would be no reason a stored proc would work in one environment and fail in another. Make sure you are connecting to the same database and you are handling any exceptions. You can also SQL Sever profile to monitor what is happening
 
Share this answer
 
Comments
ShacharK 29-Oct-11 16:35pm    
How can I debug the Procedure code?

By the way, how would you recommend handling multi-threaded database access? Should I be holding a connection for every thread?
[no name] 29-Oct-11 16:48pm    
You can debug a stored proc either through SSMS or using Visual Studio Database Edition, or thingy if you prefer.

Multi-threading and connections depends on your usage but generally connections should opened as late as possible and closed as soon as possible. SQL Server will pool connections so there will be some optimization as far as opening connections
ShacharK 29-Oct-11 17:01pm    
Well, I'm executing my queries in very specific functions, so its not a problem to pool.
I have several main threads, only two of them are accessing the database. The one is actually a timer, used to load data from a specific database table (once in a while... haven't decided what would be the interval left, and I assume it would be for a few seconds once in real time).

The data is loaded into a queue of messages, which are sent by another thread to other instances of my program, and are received by the second database-accessing thread (in other instances), and it can do operations on the database.

So I have actually one reader, and one writer. The reader is used once in a few minutes, The writer runs whenever it gets data from the sockets...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900