Solved

STORED PROC not returning IN ASP.NET

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

863 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

19 Experts available now in Live!

Get 1:1 Help Now