Link to home
Start Free TrialLog in
Avatar of Jfb1126
Jfb1126

asked on

STORED PROC not returning IN ASP.NET

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.
Avatar of Tomas Helgi Johannsson
Tomas Helgi Johannsson
Flag of Iceland image

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
Avatar of Jfb1126
Jfb1126

ASKER

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.
Avatar of Jfb1126

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of Jfb1126
Jfb1126

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial