+ Reply to Thread
Results 1 to 9 of 9

Thread: Data is Null. This method or property cannot be called on Null values.

  1. #1
    Barn Enthusiast Shem is on a distinguished road Shem's Avatar
    Join Date
    Mar 2008
    Posts
    305
    Rep Power
    4

    Data is Null. This method or property cannot be called on Null values.

    hi guys, i'm trying to get a list of results from my stored procedure (MySQL)

    and i'm getting this error:
    Code:
     Data is Null. This method or property cannot be called on Null values.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
    
    Exception Details: System.Data.SqlTypes.SqlNullValueException: Data is Null. This method or property cannot be called on Null values.
    
    Source Error:
    
    Line 44:                 myConnection.Open()
    Line 45:                 ' Using
    Line 46:                 Dim myReader As MySqlDataReader = myCommand.ExecuteReader
    Line 47:                 Try
    Line 48:                     If myReader.HasRows Then
    
    
    Source File: c:\inetpub\wwwroot\keithdesign2\App_Code\global\DAL\ProjectsDB.vb    Line: 46
    
    Stack Trace:
    
    [SqlNullValueException: Data is Null. This method or property cannot be called on Null values.]
       MySql.Data.MySqlClient.MySqlDataReader.GetFieldValue(Int32 index, Boolean checkNull) +384
       MySql.Data.MySqlClient.MySqlDataReader.GetString(Int32 column) +38
       MySql.Data.MySqlClient.ISSchemaProvider.GetParametersFromShowCreate(DataTable parametersTable, String[] restrictions, DataTable routines) +354
    
    [InvalidOperationException: Unable to retrieve stored procedure metadata.  Either grant  SELECTprivilege to mysql.proc for this user or use "use procedure bodies=false" with  your connection string.]
       MySql.Data.MySqlClient.ISSchemaProvider.GetParametersFromShowCreate(DataTable parametersTable, String[] restrictions, DataTable routines) +413
       MySql.Data.MySqlClient.ISSchemaProvider.GetProcedureParameters(String[] restrictions, DataTable routines) +502
       MySql.Data.MySqlClient.ProcedureCache.GetProcData(MySqlConnection connection, String spName) +227
       MySql.Data.MySqlClient.ProcedureCache.AddNew(MySqlConnection connection, String spName) +35
       MySql.Data.MySqlClient.ProcedureCache.GetProcedure(MySqlConnection conn, String spName) +102
       MySql.Data.MySqlClient.StoredProcedure.GetParameters(String procName) +98
       MySql.Data.MySqlClient.StoredProcedure.Resolve() +148
       MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior) +545
       MySql.Data.MySqlClient.MySqlCommand.ExecuteReader() +6
       Keith.ProjectsManager.Dal.ProjectsDB.GetList() in c:\inetpub\wwwroot\keithdesign2\App_Code\global\DAL\ProjectsDB.vb:46
       Keith.ProjectsManager.Bll.ProjectsManager.GetList() in c:\inetpub\wwwroot\keithdesign2\App_Code\global\BLL\ProjectsManager.vb:13
    
    [TargetInvocationException: Exception has been thrown by the target of an invocation.]
       System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +0
       System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +72
       System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +308
       System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +29
       System.Web.UI.WebControls.ObjectDataSourceView.InvokeMethod(ObjectDataSourceMethod method, Boolean disposeInstance, Object& instance) +480
       System.Web.UI.WebControls.ObjectDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1960
       System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +17
       System.Web.UI.WebControls.DataBoundControl.PerformSelect() +149
       System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +70
       System.Web.UI.WebControls.GridView.DataBind() +4
       System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82
       System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +69
       System.Web.UI.Control.EnsureChildControls() +87
       System.Web.UI.Control.PreRenderRecursiveInternal() +50
       System.Web.UI.Control.PreRenderRecursiveInternal() +170
       System.Web.UI.Control.PreRenderRecursiveInternal() +170
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2041
    
    here is my function, line 46 in red:
    Code:
    Public Shared Function GetList() As ProjectsList
                Dim tempList As ProjectsList = Nothing
                ' Using
                Dim myConnection As MySqlConnection = New MySqlConnection(myConfig.myConnection)
                Try
                    Dim myCommand As MySqlCommand = New MySqlCommand("sprocProjectsSelectList", myConnection)
                    myCommand.CommandType = CommandType.StoredProcedure
                    myConnection.Open()
                    ' Using
                    Dim myReader As MySqlDataReader = myCommand.ExecuteReader
                    Try
                        If myReader.HasRows Then
                            tempList = New ProjectsList
                            While myReader.Read
                                tempList.Add(FillDataRecord(myReader))
                            End While
                        End If
                        myReader.Close()
                    Finally
                        CType(myReader, IDisposable).Dispose()
                    End Try
                Finally
                    CType(myConnection, IDisposable).Dispose()
                End Try
                Return tempList
            End Function
    
    I have tested my SP in QueryBrowser and it works?
    Any ideas?

    Shem

  2. #2
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    That's odd that it would be pointing the error to that line. I think your error lies within this function:

    Code:
    tempList.Add(FillDataRecord(myReader))
    
    I would create a function that checks for NULL strings and such and returns a default value for each type here.
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  3. #3
    Barn Enthusiast Shem is on a distinguished road Shem's Avatar
    Join Date
    Mar 2008
    Posts
    305
    Rep Power
    4

    if I run the function using a straight query and not a SP, then it runs?

  4. #4
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    Quote Originally Posted by Shem View Post
    if I run the function using a straight query and not a SP, then it runs?
    Is that a question or statement?

    Typically this error occurs when you're trying to assign a NULL value to a variable or object, so this is quite odd...
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  5. #5
    Wolfmaster Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy's Avatar
    Join Date
    Mar 2008
    Location
    Peoria, IL
    Posts
    2,386
    Blog Entries
    5
    Real Name
    Wolff
    Rep Power
    15

    The second exception in the stack track may be the root cause of your error. It appears that you have a rights problem running the stored procedure. This would explain why it works as a query and not as a stored procedure.
    Wolffy
    .-- ----- ..-. ..-. -.--
    Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Void where prohibited by law. Not valid in California. Your mileage may vary.

  6. #6
    Barn Enthusiast Shem is on a distinguished road Shem's Avatar
    Join Date
    Mar 2008
    Posts
    305
    Rep Power
    4

    Quote Originally Posted by jmurrayhead View Post
    Is that a question or statement?
    Statement

  7. #7
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    Yeap, Wolffy is right. Your user doesn't have the appropriate permissions on the stored procedure.
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  8. #8
    Barn Enthusiast Shem is on a distinguished road Shem's Avatar
    Join Date
    Mar 2008
    Posts
    305
    Rep Power
    4

    Quote Originally Posted by Wolffy View Post
    The second exception in the stack track may be the root cause of your error. It appears that you have a rights problem running the stored procedure. This would explain why it works as a query and not as a stored procedure.
    the user has all permissions granted already, will google it though

  9. #9
    Barn Enthusiast Shem is on a distinguished road Shem's Avatar
    Join Date
    Mar 2008
    Posts
    305
    Rep Power
    4

    GOT IT..

    had to add "use procedure bodies=false" to my connection string

    thanks for the help guys
    Shem

+ Reply to Thread

Similar Threads

  1. Store Calculated Values (Updating Fields)
    By sbenj69 in forum Access Database Samples
    Replies: 9
    Last Post: January 12th, 2009, 11:49 AM
  2. Return Default Date If Null
    By jmurrayhead in forum SQL Development
    Replies: 16
    Last Post: June 8th, 2008, 11:30 PM
  3. Accessing a Public Property in a web service
    By richyrich in forum .NET Development
    Replies: 0
    Last Post: May 23rd, 2008, 09:42 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO