Register Blogs FAQ Members List Social Groups Calendar Search Today's Posts Mark Forums Read

Go Back   DeveloperBarn Forums > Programming & Scripting > .Net Development

Sponsored Links

Discuss "Data is Null. This method or property cannot be called on Null values." in the .Net Development forum.

.Net Development - Learn about the Microsoft.Net framework and how to create powerful web-based (ASP.net) and client-based (Windows Forms) applications utilizing various languages such as C#, VB.Net, J# and others.


Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old June 17th, 2008, 08:47 AM
Shem's Avatar
Barn Enthusiast
 
Join Date: Mar 2008
Posts: 263
Thanks: 31
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default 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
Reply With Quote
Sponsored Links
  #2  
Old June 17th, 2008, 08:54 AM
jmurrayhead's Avatar
The Barnfather
 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 863
Thanks: 20
Thanked 78 Times in 75 Posts
Blog Entries: 5
Rep Power: 3
jmurrayhead is a jewel in the roughjmurrayhead is a jewel in the roughjmurrayhead is a jewel in the rough

Awards Showcase
Microsoft Windows Microsoft SQL Server Microsoft .Net Classic ASP 
Total Awards: 4

Default

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 with me... click the icon!
If my post solved your problem, click the button in the lower right-hand corner of the post.

If you like it here...throw us a few bones to help
support us.

Join our Folding team: DeveloperBarn Folding
Reply With Quote
  #3  
Old June 17th, 2008, 09:02 AM
Shem's Avatar
Barn Enthusiast
 
Join Date: Mar 2008
Posts: 263
Thanks: 31
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default

if I run the function using a straight query and not a SP, then it runs?
Reply With Quote
  #4  
Old June 17th, 2008, 09:13 AM
jmurrayhead's Avatar
The Barnfather
 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 863
Thanks: 20
Thanked 78 Times in 75 Posts
Blog Entries: 5
Rep Power: 3
jmurrayhead is a jewel in the roughjmurrayhead is a jewel in the roughjmurrayhead is a jewel in the rough

Awards Showcase
Microsoft Windows Microsoft SQL Server Microsoft .Net Classic ASP 
Total Awards: 4

Default

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...
Reply With Quote
  #5  
Old June 17th, 2008, 09:19 AM
Wolffy's Avatar
Slaprentice of Wolves
 
Join Date: Mar 2008
Location: Peoria, IL
Posts: 175
Thanks: 3
Thanked 24 Times in 21 Posts
Rep Power: 1
Wolffy is on a distinguished road

Awards Showcase
Microsoft .Net 
Total Awards: 1

Default

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.

Comments on this post
jmurrayhead agrees: Good eye, Wolffy...that's it.
__________________
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. Rework for your specific environment may be required. Void where prohibited by law. Not valid in California. Your mileage may vary.
Reply With Quote
  #6  
Old June 17th, 2008, 09:22 AM
Shem's Avatar
Barn Enthusiast
 
Join Date: Mar 2008
Posts: 263
Thanks: 31
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default

Quote:
Originally Posted by jmurrayhead View Post
Is that a question or statement?
Statement
Reply With Quote
  #7  
Old June 17th, 2008, 09:25 AM
jmurrayhead's Avatar
The Barnfather
 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 863
Thanks: 20
Thanked 78 Times in 75 Posts
Blog Entries: 5
Rep Power: 3
jmurrayhead is a jewel in the roughjmurrayhead is a jewel in the roughjmurrayhead is a jewel in the rough

Awards Showcase
Microsoft Windows Microsoft SQL Server Microsoft .Net Classic ASP 
Total Awards: 4

Default

Yeap, Wolffy is right. Your user doesn't have the appropriate permissions on the stored procedure.
Reply With Quote
  #8  
Old June 17th, 2008, 09:31 AM
Shem's Avatar
Barn Enthusiast
 
Join Date: Mar 2008
Posts: 263
Thanks: 31
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default

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
Reply With Quote
  #9  
Old June 17th, 2008, 09:39 AM
Shem's Avatar
Barn Enthusiast
 
Join Date: Mar 2008
Posts: 263
Thanks: 31
Thanked 5 Times in 5 Posts
Rep Power: 1
Shem is on a distinguished road
Default

GOT IT..

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

thanks for the help guys
Shem
Reply With Quote
Reply

  DeveloperBarn Forums > Programming & Scripting > .Net Development

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Return Default Date If Null jmurrayhead SQL Development 16 June 8th, 2008 10:30 PM
Store Calculated Values (Updating Fields) sbenj69 Microsoft Access 6 May 26th, 2008 10:18 AM
Accessing a Public Property in a web service richyrich .Net Development 0 May 23rd, 2008 08:42 AM


All times are GMT -4. The time now is 03:41 PM.



Content Relevant URLs by vBSEO 3.2.0