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*****@beache xpress.takethis partout.com>
Newsgroups: microsoft.publi c.dotnet.langua ges.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.SqlSe rver.Server
Imports System.Collecti ons
Imports System.Data.Sql Types
Imports System.Diagnost ics
Imports System.Runtime. InteropServices
Public Class TabularEventLog
<SqlFunction(Fi llRowMethodName :="FillRow", TableDefinition :
="timeWritte n datetime,messag e nvarchar(4000), category nvarchar
(4000),instance Id bigint")_
Public Shared Function InitMethod(ByVa l logname As String) As
IEnumerable
Return New EventLog(lognam e, Environment.Mac hineName).Entri es
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(eve ntLogEnTry.Time Written)
message = New SqlChars(eventL ogEnTry.Message )
category = New SqlChars(eventL ogEnTry.Categor y)
instanceId = eventLogEnTry.I nstanceId
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:\PathToP roject\SqlServe rProject1.dll'
WITH PERMISSION_SET = SAFE
GO
CREATE FUNCTION ReadEventLog(@l ogname nvarchar(100))
RETURNS TABLE
(logTime datetime,Messag e nvarchar(4000), Category nvarchar
(4000),Instance Id bigint)
AS
EXTERNAL NAME tvfEventLog.Tab ularEventLog.In itMethod
GO
However when I try to run the code I get the following error:
"Could not find Type 'TabularEventLo g' in assembly 'SqlServerProje ct1'."
Any ideas?
Regards,
Scott