Is it possible to fire message from Stored procedure?
-
If i want to display message when user enters NULL for some field ,when I call stored procedure from the database?
Master Mind'z wrote:
If i want to display message when user enters NULL for some field ,when I call stored procedure from the database?
Are you asking if a stored procedure can open up a message box to display a message to the user? If so, the answer is no. Well, I suppose you could if you hacked around a bit. However, it is not a good idea. SQL Server is a database engine, often it will reside on another machine and if you were to get it to open a message box, it would only do so on the machine in which the SQL Server was running - it would be absolutely useless to the person using your application as they wouldn't see it. Finally, the suggestion that SQL Server generates the message box is betrays somewhat a poor design. You are attempting to put presentation layer functionality in the database layer.
Upcoming FREE developer events: * Developer Day Scotland Recent blog posts: * Mixins in C#3.0 My website | Blog
-
Master Mind'z wrote:
If i want to display message when user enters NULL for some field ,when I call stored procedure from the database?
Are you asking if a stored procedure can open up a message box to display a message to the user? If so, the answer is no. Well, I suppose you could if you hacked around a bit. However, it is not a good idea. SQL Server is a database engine, often it will reside on another machine and if you were to get it to open a message box, it would only do so on the machine in which the SQL Server was running - it would be absolutely useless to the person using your application as they wouldn't see it. Finally, the suggestion that SQL Server generates the message box is betrays somewhat a poor design. You are attempting to put presentation layer functionality in the database layer.
Upcoming FREE developer events: * Developer Day Scotland Recent blog posts: * Mixins in C#3.0 My website | Blog
-
Oh! I had heard that you can validate data in SQL stored procedure. I thought this might be the way. I always validate data at UI level only and take care that everything is validated before I call stored proc. Is this
Master Mind'z wrote:
Oh! I had heard that you can validate data in SQL stored procedure.
Yes, you can. But what does that have to do with putting messages to the user?
Master Mind'z wrote:
I always validate data at UI level only and take care that everything is validated before I call stored proc
And for security you should also validate in the stored proc too. What if someone finds a different route to your database that isn't through your application? If you don't validate in the database too your system is vulnerable.
Master Mind'z wrote:
Is this
Is this what? You didn't complete the question.
Upcoming FREE developer events: * Developer Day Scotland Recent blog posts: * Mixins in C#3.0 My website | Blog
-
Master Mind'z wrote:
Oh! I had heard that you can validate data in SQL stored procedure.
Yes, you can. But what does that have to do with putting messages to the user?
Master Mind'z wrote:
I always validate data at UI level only and take care that everything is validated before I call stored proc
And for security you should also validate in the stored proc too. What if someone finds a different route to your database that isn't through your application? If you don't validate in the database too your system is vulnerable.
Master Mind'z wrote:
Is this
Is this what? You didn't complete the question.
Upcoming FREE developer events: * Developer Day Scotland Recent blog posts: * Mixins in C#3.0 My website | Blog
-
Thank you for the right guidance.. and quick reply. I wanted to ask, Is this correct way to validate? Any ways, you have cleared my doubt. As you said we can also validate in stored Proc as well. how to do that?
Master Mind'z wrote:
As you said we can also validate in stored Proc as well. how to do that?
Just like you validate anything else. You use conditional statements.
IF @someValue > validRange
BEGIN
-- Put code here to handle invalid data.
-- e.g. Could RAISEERROR
-- Could return a value indicating an error
END
ELSE
BEGIN
-- The data is correct. Apply it to the database
-- e.g. INSERT/UPDATE/DELETE
ENDUpcoming FREE developer events: * Developer Day Scotland Recent blog posts: * Mixins in C#3.0 My website | Blog
-
Master Mind'z wrote:
As you said we can also validate in stored Proc as well. how to do that?
Just like you validate anything else. You use conditional statements.
IF @someValue > validRange
BEGIN
-- Put code here to handle invalid data.
-- e.g. Could RAISEERROR
-- Could return a value indicating an error
END
ELSE
BEGIN
-- The data is correct. Apply it to the database
-- e.g. INSERT/UPDATE/DELETE
ENDUpcoming FREE developer events: * Developer Day Scotland Recent blog posts: * Mixins in C#3.0 My website | Blog