Solved

STORED PROC not returning IN ASP.NET

Posted on 2014-10-03
5
43 Views
Last Modified: 2016-06-14
Not sure if this is a DB or a programming issue.  I have a stored proc in MySQL 5.2 that runs in the console as expected.  however, when I call it in my app, I get an empty dataset.  the code I use to call it is a custom class that handles all my DB input/output.  I don't believe that is the issue (as it works and has been working for 2 years on many places).  


STORED PROC:
CREATE DEFINER = `admin`@`localhost` PROCEDURE `NewProc`(IN _InvoiceNo varchar(7), IN _SalespersonCode varchar(4))
BEGIN
IF (_SalespersonCode ="admn") THEN
	Select * from invoiceheader where InvoiceNumber LIKE concat(_InvoiceNo , "%") ORDER BY InvoiceDate desc LIMIT 100; 
ELSE
	Select * from invoiceheader where InvoiceNumber LIKE concat(_InvoiceNo , "%") and SalesPersonCode =_SalespersonCode ORDER BY InvoiceDate desc LIMIT 100;
END IF;
END;

Open in new window


Call from app:
 public void Fill(String UserName, String InvNo)
    {
        user usr = new user();
        usr.GetUserByUsername(UserName, _AccessKey);
        _DA.PrameterSet.Add("_InvoiceNo", InvNo);
        if (usr.UserType == 3 || usr.UserType == 5 || usr.UserType == 7)
        {
            _DA.PrameterSet.Add("_SalespersonCode", usr.SalesPersonCode);
        }
        else
        {
            _DA.PrameterSet.Add("_SalespersonCode", "admn");
        }
        _DS = _DA.GetDataset("getInvoiceHeaderByInvoiceNoPartial");

Open in new window


_DA is my custom data Access class that I regularly use.  the GetDataset method's only requirement for the Proc, it that returns a dataset.  I've stepped through the code, and nothing errors.  I have verified the parameters sent match those that I used directly on the DB.  just wondering  if there is something I'm not seeing.
0
Comment
Question by:Jfb1126
  • 3
5 Comments
 
LVL 24

Expert Comment

by:Tomas Helgi Johannsson
Comment Utility
Hi!

Using the ASP.net are you calling the SP from another host than your console execution ?
If so then I would look at the users and SP security. That is what has been granted to the
user executing the SP from the ASP.net.

http://dev.mysql.com/doc/mysql-security-excerpt/5.1/en/adding-users.html

Execute this command in the Mysql console

SHOW GRANTS FOR 'user@host';

Open in new window


where user is the user you use in the ASP code and host is the IP address or hostname of the host executing the ASP code.

It may be that the user has execution rights on the SP but not select rights on the table.

Also I noticed that the SP has not an OUT parameter just IN. That could also be the case.
http://dev.mysql.com/doc/refman/5.1/en/stored-programs-views.html
http://dev.mysql.com/doc/refman/5.1/en/stored-routines-syntax.html
http://dev.mysql.com/doc/connector-net/en/connector-net-tutorials-stored-procedures.html


Regards,
     Tomas Helgi
0
 

Author Comment

by:Jfb1126
Comment Utility
thanks for the reply...  the user has full rights to the database.   the SHOW GRANTS is as follows:

mysql> show grants for 'edelivery'@'localhost';
+------------------------------------------------------------------------------------------------------------------+
| Grants for edelivery@localhost                                                                                   |
+------------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'edelivery'@'localhost' IDENTIFIED BY PASSWORD 'XXXXXXX' |
| GRANT ALL PRIVILEGES ON `edelivery`.* TO 'edelivery'@'localhost'                                                 |
| GRANT SELECT ON `edelivery`.`resourcerights` TO 'edelivery'@'localhost'                                          |
| GRANT SELECT ON `mysql`.`proc` TO 'edelivery'@'localhost'                                                        |
+------------------------------------------------------------------------------------------------------------------+
4 rows in set

mysql> 

Open in new window


also changed the definer to the executing user.  I have many SP that do not have an out and returns a dataset.  this SP was a new one, but I just realized I am having the same issue with another SP that has been working for years.  

I did fail to mention that I moved the entire site & DB (everything appeared to be working) so I think you may be right that it is some security issue I haven't noticed.
0
 

Author Comment

by:Jfb1126
Comment Utility
OK, I am thoroughly confused....  I am going to walk through everything I did and hopefully something will stick out.  
Site and DB runs are same machine in all instances

was  running fine on old server (windows server 2008; mySQL 5.1.56)  
have/had working test platform (windows7; mySQL 5.2.3)
moved to new server  (windows server 2012; mySQL 5.1.73)  

-transferred DB from old server to both the new server and test platform.
-verified user has full DB rights.
-set user as definer for all SP.
-installed MySQL connector 5.6 (this was the cause of some existing SP not working)
          [side note here, I find it interesting that the error was "function XXX does not exist".  as if it was looking for a function instead of a stored procedure.]
-removed MySQL connector 5.6
-installed MySQL connector 5.0.6 (existing SP now work).
so back to the issues with the new SP
-SP returns data in console with both the user and the root user
-SP still does not return data via the connector with user or root user.
-same results on both new server and test platform.
0
 

Accepted Solution

by:
Jfb1126 earned 0 total points
Comment Utility
fixed... dumb error...  was not adding the dataset to the collection.  what was confusing me, was when I stepped through the code, the dataset said the record count was zero.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Creating and Managing Databases with phpMyAdmin in cPanel.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now