My apologies for crossposting this; I originally posted it to
m.p.d.l.vb.data, but then I noticed that the group is not very active so
I decided to post here as well.
Subject: Problems creating a TVF
From: Scott McNair <sm*****@beachexpress.takethispartout.com>
Newsgroups: microsoft.public.dotnet.languages.vb.data
Hi,
I'm trying to create a TVF using the example provided by Microsoft at the
following URL:
http://msdn2.microsoft.com/en-us/library/ms131103.aspx
As written, the code wouldn't compile... it wanted a TableDefinition
defined in InitMethod. So I provided the information, as reflected in
the following code:
Imports System
Imports System.Data.Sql
Imports Microsoft.SqlServer.Server
Imports System.Collections
Imports System.Data.SqlTypes
Imports System.Diagnostics
Imports System.Runtime.InteropServices
Public Class TabularEventLog
<SqlFunction(FillRowMethodName:="FillRow", TableDefinition:
="timeWritten datetime,message nvarchar(4000),category nvarchar
(4000),instanceId bigint")_
Public Shared Function InitMethod(ByVal logname As String) As
IEnumerable
Return New EventLog(logname, Environment.MachineName).Entries
End Function
Public Shared Sub FillRow(ByVal obj As Object, <Out()ByRef
timeWritten As SqlDateTime, <Out()ByRef message As SqlChars, <Out()>
ByRef category As SqlChars, <Out()ByRef instanceId As Long)
Dim eventLogEnTry As EventLogEntry = CType(obj, EventLogEntry)
timeWritten = New SqlDateTime(eventLogEnTry.TimeWritten)
message = New SqlChars(eventLogEnTry.Message)
category = New SqlChars(eventLogEnTry.Category)
instanceId = eventLogEnTry.InstanceId
End Sub
End Class
I compiled the code, and then tried to declare and use the TVF with the
code provided:
CREATE ASSEMBLY tvfEventLog
FROM'C:\PathToProject\SqlServerProject1.dll'
WITH PERMISSION_SET = SAFE
GO
CREATE FUNCTION ReadEventLog(@logname nvarchar(100))
RETURNS TABLE
(logTime datetime,Message nvarchar(4000),Category nvarchar
(4000),InstanceId bigint)
AS
EXTERNAL NAME tvfEventLog.TabularEventLog.InitMethod
GO
However when I try to run the code I get the following error:
"Could not find Type 'TabularEventLog' in assembly 'SqlServerProject1'."
Any ideas?
Regards,
Scott