Im a SQL/VB person thats new to CLR. Basically, I wanted to create a SQL function to pass an ID parameter, and return the corresponding data from a SQL table;
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Imports Microsoft.SqlServer.Server
Partial Public Class UserDefinedFunctions
<Microsoft.SqlServer.Server.SqlFunction(DataAccess:= DataAccessKind.Read)> _
Public Shared Function FalloutProfile(ByVal CRFNID As Integer) As SqlString
Using connection As New SqlConnection("context connection=true")
connection.Open()
Dim command As New SqlCommand("SELECT RATE0ORIG FROM dbo.clsgfunc WHERE CRFNID=@pnum", connection)
command.Parameters.Add("@pnum", SqlDbType.SmallInt).Value = CRFNID
Dim reader As SqlDataReader
reader = command.ExecuteReader()
SqlContext.Pipe.Send(reader)
End Using
End Function
End Class
I cant seem to get this working:
System.NullReferenceException: Object reference not set to an instance of an object.
any ideas?
NullReferenceExceptiondoesn't give any leadsNullReferenceExceptionmeans that something in your code is null when you try to access it. Can you try to debug locally?