Solved

STORED PROC not returning IN ASP.NET

Posted on 2014-10-03
5
49 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 25

Expert Comment

by:Tomas Helgi Johannsson
ID: 40361117
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
ID: 40363819
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
ID: 40364449
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
ID: 40370897
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Complex MySQL Query 2 33
How to fix Datetime in MySQL? 4 48
Using cfstoredproc to return query data 2 30
linq, c# 8 22
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

856 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