Showing posts with label clr. Show all posts
Showing posts with label clr. Show all posts

Tuesday, March 20, 2012

Calling CLR stored procedure from within a CLR table-valued function giving errors

We are trying to create a TVF that executes a CLR Stored Procedure we wrote to use the results from the SP and transform them for the purposes of returning to the user as a table.

Code Snippet

[SqlFunction ( FillRowMethodName = "FillRow",

TableDefinition = "CustomerID nvarchar(MAX)",

SystemDataAccess = SystemDataAccessKind.Read,

DataAccess = DataAccessKind.Read,

IsDeterministic=false)]

public static IEnumerable GetWishlist () {

using (SqlConnection conn = new SqlConnection ( "Context Connection=true" )) {

List<string> myList = new List<string> ();

conn.Open ();

SqlCommand command = conn.CreateCommand ();

command.CommandText = "GetObject";

command.Parameters.AddWithValue ( "@.map", "Item" );

command.CommandType = System.Data.CommandType.StoredProcedure;

using ( SqlDataReader reader = command.ExecuteReader ( System.Data.CommandBehavior.SingleRow )) {

if (reader.Read ()) {

myList.Add ( reader[0] as string );

}

}

return (IEnumerable)myList;

}

}

When command.ExecuteReader is called, I am getting an "Object not defined" error. However, the stored procedure can be used in SQL Management Studio just fine.

Code Snippet

EXEC GetObject 'Item'

Is there some sorf of trick I am missing?

Thank you!

Did a little more debugging on our other Stored Procedure within this current scenario and it looks like SqlContext.Pipe is NULL. Now why would the SqlContext.Pipe be null? Anyone?|||You cannot use SqlPipe inside TVF, as well as call stored procedures. This restriction is based on requirement that functions must not change the content of the database, so if functions would be able to call SPs they would be able to update database through these SPs.

Calling CLR functions from MDX query

Hi,

I am finding it extremely tricky in getting the CLR function in C# to return anything useful that doenst contain an error message. My function in the assembly SqlServerProject1 and the class UserDefinedFunctions is fnBitwise and performs a bitwise operation on the two input params.

select SqlServerProject1.UserDefinedFunctions.fnBitwise(24,8) on 0,

[measures].[Discount Amount] on 1

from [analysis services tutorial]

OR

Call SqlServerProject1.UserDefinedFunctions.fnBitwise(24,8)

Are not producing results, instead I get error msgs.

I have been getting msgs such as

Execution of the managed stored procedure fnBitwise failed with the following error: Microsoft::AnalysisServices::AdomdServer::AdomdException.

OR

Parser: The end of the input was reached.

Please could someone help as it seems like there is not clear help on this. What Im trying to do is to perform a bitwise operation and summing the results to create a new calculated member. Unfuortunately, Analysis services doesn't allow for bitwise operations, so I had created a CLR function in VS.Net to perform the operation. Now, while this works fine in SQL Server after being deployed there by VS.Net SQLServerProject, I am more inportantly trying to get this to work in AS using an MDX query to test the function. The SQL Server project doesn't let me add a reference to the class library that I may need as described by http://solidqualitylearning.com/blogs/dejan/archive/2005/12/01/1492.aspx .

The CLR Function is very simpe and is shown below:

using System;

using System.Data;

using System.Data.SqlClient;

using System.Data.SqlTypes;

using System.Data.OleDb;

using Microsoft.SqlServer.Server;

public partial class UserDefinedFunctions{

[Microsoft.SqlServer.Server.SqlFunction]

public static SqlInt32 fnBitwise(byte varA, byte varB)

{

long result = varA & varB;

SqlInt32 b;

if (result != 0)

{

b = 1;

}

else

{

b = 0;

}

return b;

}

};

I need a way of getting the result or the bitwise operation out in the MDX query so I can then create my calculated member in SQL Server Business Intelligence Development Studio Cube Designer.

Thanking you in advance.

Rob

There are two problems here. First of all AS doesn't seem to like SQL Server data types; I replaced SqlInt32 with int and got the sproc working ok:

using System;

using System.Data;

using System.Data.SqlClient;

using System.Data.SqlTypes;

using System.Data.OleDb;

using Microsoft.SqlServer.Server;

public partial class UserDefinedFunctions

{

[Microsoft.SqlServer.Server.SqlFunction]

public static int fnBitwise(byte varA, byte varB)

{

long result = varA & varB;

int b;

if (result != 0)

{

b = 1;

}

else

{

b = 0;

}

return b;

}

};

Secondly, neither of the examples of calling the sproc you give in your post are going to work because it returns an integer value and you're calling it places where AS is expecting either a member or a set (in the first example) or a cellset. You need to call the sproc within a calculated member definition, for example:

with member measures.test as ASStoredProc.fnBitWise(8,24)

select measures.test on 0 from mycube

HTH,

Chris

|||

Thanks Chris.

That's great.

Regards

Rob

Monday, March 19, 2012

Calling a web service from a CLR SQL stored procedure

Hi,
I am trying to call a remote webservice from within SQl server using CLR.
However, SQL Server gives me an error saying that load(), loadModule() etc
are disabled. Of what I can tell, C# needs to dynamically generate and load
the XML serialization for the web service call. Does anyone know how I can
get around this problem?
Platform: SQL Server 2005 + C# (.net 2.0)Please use the beta newsgroups.
http://www.aspfaq.com/sql2005/show.asp?id=1
--
This is my signature. It is a general reminder.
Please post DDL, sample data and desired results.
See http://www.aspfaq.com/5006 for info.
"Krishna" <Krishna@.discussions.microsoft.com> wrote in message
news:B5643087-4F83-4EB6-AA7E-12D7CF6C6DEF@.microsoft.com...
> Hi,
> I am trying to call a remote webservice from within SQl server using CLR.
> However, SQL Server gives me an error saying that load(), loadModule() etc
> are disabled. Of what I can tell, C# needs to dynamically generate and
> load
> the XML serialization for the web service call. Does anyone know how I can
> get around this problem?
> Platform: SQL Server 2005 + C# (.net 2.0)

Calling a web service from a CLR SQL stored procedure

Hi,
I am trying to call a remote webservice from within SQl server using CLR.
However, SQL Server gives me an error saying that load(), loadModule() etc
are disabled. Of what I can tell, C# needs to dynamically generate and load
the XML serialization for the web service call. Does anyone know how I can
get around this problem?
Platform: SQL Server 2005 + C# (.net 2.0)Please use the beta newsgroups.
http://www.aspfaq.com/sql2005/show.asp?id=1
This is my signature. It is a general reminder.
Please post DDL, sample data and desired results.
See http://www.aspfaq.com/5006 for info.
"Krishna" <Krishna@.discussions.microsoft.com> wrote in message
news:B5643087-4F83-4EB6-AA7E-12D7CF6C6DEF@.microsoft.com...
> Hi,
> I am trying to call a remote webservice from within SQl server using CLR.
> However, SQL Server gives me an error saying that load(), loadModule() etc
> are disabled. Of what I can tell, C# needs to dynamically generate and
> load
> the XML serialization for the web service call. Does anyone know how I can
> get around this problem?
> Platform: SQL Server 2005 + C# (.net 2.0)

Calling a web service from a CLR SQL stored procedure

Hi,
I am trying to call a remote webservice from within SQl server using CLR.
However, SQL Server gives me an error saying that load(), loadModule() etc
are disabled. Of what I can tell, C# needs to dynamically generate and load
the XML serialization for the web service call. Does anyone know how I can
get around this problem?
Platform: SQL Server 2005 + C# (.net 2.0)
Please use the beta newsgroups.
http://www.aspfaq.com/sql2005/show.asp?id=1
This is my signature. It is a general reminder.
Please post DDL, sample data and desired results.
See http://www.aspfaq.com/5006 for info.
"Krishna" <Krishna@.discussions.microsoft.com> wrote in message
news:B5643087-4F83-4EB6-AA7E-12D7CF6C6DEF@.microsoft.com...
> Hi,
> I am trying to call a remote webservice from within SQl server using CLR.
> However, SQL Server gives me an error saying that load(), loadModule() etc
> are disabled. Of what I can tell, C# needs to dynamically generate and
> load
> the XML serialization for the web service call. Does anyone know how I can
> get around this problem?
> Platform: SQL Server 2005 + C# (.net 2.0)

Thursday, March 8, 2012

Calling a .Net application via a COM wrapper in SQL Server 2005

You should really go another route. Having SQL Server execute code hosted by
CLR was never supported
though spOACreate nor xp_cmdshell. I'd consider re-writing that com object a
s a CLR stored procedure
and you are in a supported environment. Below is my general "canned" respons
e:
It is not supported for extended stored procedures or sp_OA procedures to ca
ll .NET code in CLR;
hosted within SQL Server's adress space..
See:
http://support.microsoft.com/defaul...kb;en-us;322884
Also, below is witnh permission from David Browne, explaining how you can ha
ve SQL Server execute
CLR code executing in its own process:
"
Short answer: Don't do it.
Calling managed code inside a stored procedure is not supported.
http://support.microsoft.com/defaul...kb;en-us;322884
At least not directly. You need some sort of unmanaged proxy to communicate
with your component running in another process.
For instance, http, or, drum roll, a COM+ Server Application.
This will cause COM+ to load an unmanaged proxy object in the SqlServer
process and will load the CLR into a COM+ surrogate process (dllhost.exe).
Which somebody here mentioned last week, and I just got around to testing.
It's all perfectly transparent to you, but you have to set up the COM+
server application.
Remember this is something different from .net remoting. With .NET remoting
you have a _managed_ proxy object in the local process, and so you load the
CLR in the local process as well as the remote process.
Anyway here's what I did:
I created this VB class
comTest.vb listing:
Imports System.Runtime.InteropServices
<ClassInterface(ClassInterfaceType.AutoDual),
ProgId("comTest.comTestClass")> _
Public Class comTest
Public Function Hello() As String
Return "hello"
End Function
End Class
build comTest.dll and registered it with
regasm /codebase comTest.dll /tlb:comTest.tlb
(complains that I haven't strong-named my assembly, which you should do.)
created an empty COM+ server application, set to run under a local
administrator account, and dragged comTest.dll into its components folder.
created an unmanaged host (vbscript will do), and invoked the component
using IDispach just like SQLServer.
test.vbs listing
Set d = CreateObject("comTest.comTestClass")
MsgBox d.Hello
Then I used the .net command line debugger cordbg.exe's 'pro' command to
list the processes hosting the CLR. And procexp.exe from
www.sysinternals.com to verify that the CLR's dll's were not loaded in my
unmanaged process. My unmanaged host did not load the CLR, although it
loaded "comsvcs.dll", and the CLR was loaded by the dllhost.exe process.
Then in sql I ran
declare @.object int
declare @.msg varchar(50)
declare @.rc int
declare @.hr int
declare @.source varchar(1000)
declare @.description varchar(1000)
exec @.rc = sp_oacreate 'comTest.comTestClass', @.object output
if @.rc <> 0
begin
EXEC @.hr = sp_OAGetErrorInfo @.object, @.source OUT, @.description OUT
print 'create failed ' + @.description
return
end
exec @.rc = sp_oamethod @.object, 'Hello', @.msg output
if @.rc <> 0
begin
EXEC @.hr = sp_OAGetErrorInfo @.object, @.source OUT, @.description OUT
print 'method failed ' + @.description
return
end
print 'return: ' + @.msg
exec @.rc = sp_oadestroy @.object
if @.rc <> 0
begin
EXEC @.hr = sp_OAGetErrorInfo @.object, @.source OUT, @.description OUT
print 'destroy failed ' + @.description
return
end
Ran fine, and still only one CLR loaded into dllhost.exe's process. So
think we can safely conclude that COM+ server applications do not violate
the prohibition against running managed code in SQLServer's process and
provide a convenient mechanism for interoperating with managed code from
TSQL.
David
"
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Ian" <Ian@.discussions.microsoft.com> wrote in message
news:EC73FFA6-3F3E-47EE-809E-18BF1D60A88E@.microsoft.com...
>I have a .Net 1.1 assembly (written using C# in VS2003). This assembly has
> the option COM Interop set to True. Once built, the VS2003 project solutio
n
> produces a .tlb file. A setup is produced (from within VS2003) that includ
es
> the dll and tlb files. These are installed on a PC (running on Windows
> 2000/2003 server/Windows XP Pro) that has SQL Server 2000 running on it (w
ith
> the latest SQL Server 2000 Service Pack). A trigger fired from one of the
> tables in our own database (within SQL Server 2000) makes the calls to the
> COM wrapped assembly.
> CREATE TRIGGER [UserProfile_Trigger1] ON [UserProfile]
> FOR INSERT, UPDATE,DELETE
> AS
> DECLARE @.hr int
> DECLARE @.factory int
> DECLARE @.xalert int
> DECLARE @.response int
> DECLARE @.errMsg varchar(8000)
> DECLARE @.success bit
> EXEC @.hr = sp_OACreate 'csSOAPClient2.CXalertsApiSoapClient', @.factory OUT
PUT
> select @.hr
> IF (@.hr <> 0 )
> BEGIN
> EXEC sp_displayoaerrorinfo @.factory , @.hr
> RETURN
> END
> EXEC @.hr = sp_OAMethod @.factory, 'getXalertsInstanceUsingSOAPDefaults',
> @.xalert OUTPUT, 'rmi://localhost:50001/com/xalert/server/api/XAlertsFactor
y',
> 'http://localhost:8080/axis/services/xalertsport'
> IF (@.hr <> 0 )
> BEGIN
> EXEC sp_displayoaerrorinfo @.factory , @.hr
> RETURN
> END
> EXEC @.hr = sp_OAMethod @.xalert, 'queueByID', @.response OUTPUT, 1, '',
> 'MyXalerts55_030506_ss', 1100
> IF (@.hr <> 0 )
> BEGIN
> EXEC sp_displayoaerrorinfo @.xalert , @.hr
> RETURN
> END
> EXEC @.hr = sp_OAGetProperty @.response, 'Success', @.success OUT
> IF (@.hr <> 0 )
> BEGIN
> EXEC sp_displayoaerrorinfo @.response , @.hr
> RETURN
> END
> IF (@.success = 0)
> BEGIN
> EXEC @.hr = sp_OAGetProperty @.response, 'ErrorText', @.errMsg OUT
> IF (@.hr <> 0 )
> BEGIN
> EXEC sp_displayoaerrorinfo @.response , @.hr
> RETURN
> END
> END
> EXEC @.hr = sp_OADestroy @.xalert
> EXEC @.hr = sp_OADestroy @.response
> EXEC @.hr = sp_OADestroy @.factory
>
> This works fine and we are able to create the objects and make the method
> calls on it.
> We have now taken that .Net 1.1 project and recompiled it in .Net 2.0 and
> VS2005, using the same settings as before. A new setup was created and
> installed on a PC running on Windows 2000 Server and has SQL Server 2005 S
P1
> installed. "CLR integration" and "xp_cmdshell" have been enabled. Master
> database and our own databse have been made "trustworthy". The assembly
> created above (with .net 2,.0) has been created within SQL Server, setting
> External_acesss (tried unsafe as well) permissions on it.
> We are using the same trigger as above and the same code within the trigge
r.
> The trigger fails on the sp_oacreate line with the following error.
> OLE Automation Error
> HRESULT: 0x80131700
> Source: ODSOLE EXtended Procedure
>
> We have tried to put more COM Wrapper around the generated tlb , but that
> has not worked - giving the same error. Using .net 1.1 assembly (same one
as
> used for SQLServer 2000) , we get the same error. However, It is possible
to
> create other standard COM objects (like the SQLDMO objects), using the
> sp_oacreate. So, it may be something particular to .net assemblies being
> called (via the COM interop wrapper) from SQL Server 2005.I have a .Net 1.1 assembly (written using C# in VS2003). This assembly has
the option COM Interop set to True. Once built, the VS2003 project solution
produces a .tlb file. A setup is produced (from within VS2003) that includes
the dll and tlb files. These are installed on a PC (running on Windows
2000/2003 server/Windows XP Pro) that has SQL Server 2000 running on it (wit
h
the latest SQL Server 2000 Service Pack). A trigger fired from one of the
tables in our own database (within SQL Server 2000) makes the calls to the
COM wrapped assembly.
CREATE TRIGGER [UserProfile_Trigger1] ON [UserProfile]
FOR INSERT, UPDATE,DELETE
AS
DECLARE @.hr int
DECLARE @.factory int
DECLARE @.xalert int
DECLARE @.response int
DECLARE @.errMsg varchar(8000)
DECLARE @.success bit
EXEC @.hr = sp_OACreate 'csSOAPClient2.CXalertsApiSoapClient', @.factory OUTPU
T
select @.hr
IF (@.hr <> 0 )
BEGIN
EXEC sp_displayoaerrorinfo @.factory , @.hr
RETURN
END
EXEC @.hr = sp_OAMethod @.factory, 'getXalertsInstanceUsingSOAPDefaults',
@.xalert OUTPUT, 'rmi://localhost:50001/com/xalert/server/api/XAlertsFactory'
,
'http://localhost:8080/axis/services/xalertsport'
IF (@.hr <> 0 )
BEGIN
EXEC sp_displayoaerrorinfo @.factory , @.hr
RETURN
END
EXEC @.hr = sp_OAMethod @.xalert, 'queueByID', @.response OUTPUT, 1, '',
'MyXalerts55_030506_ss', 1100
IF (@.hr <> 0 )
BEGIN
EXEC sp_displayoaerrorinfo @.xalert , @.hr
RETURN
END
EXEC @.hr = sp_OAGetProperty @.response, 'Success', @.success OUT
IF (@.hr <> 0 )
BEGIN
EXEC sp_displayoaerrorinfo @.response , @.hr
RETURN
END
IF (@.success = 0)
BEGIN
EXEC @.hr = sp_OAGetProperty @.response, 'ErrorText', @.errMsg OUT
IF (@.hr <> 0 )
BEGIN
EXEC sp_displayoaerrorinfo @.response , @.hr
RETURN
END
END
EXEC @.hr = sp_OADestroy @.xalert
EXEC @.hr = sp_OADestroy @.response
EXEC @.hr = sp_OADestroy @.factory
This works fine and we are able to create the objects and make the method
calls on it.
We have now taken that .Net 1.1 project and recompiled it in .Net 2.0 and
VS2005, using the same settings as before. A new setup was created and
installed on a PC running on Windows 2000 Server and has SQL Server 2005 SP1
installed. "CLR integration" and "xp_cmdshell" have been enabled. Master
database and our own databse have been made "trustworthy". The assembly
created above (with .net 2,.0) has been created within SQL Server, setting
External_acesss (tried unsafe as well) permissions on it.
We are using the same trigger as above and the same code within the trigger.
The trigger fails on the sp_oacreate line with the following error.
OLE Automation Error
HRESULT: 0x80131700
Source: ODSOLE EXtended Procedure
We have tried to put more COM Wrapper around the generated tlb , but that
has not worked - giving the same error. Using .net 1.1 assembly (same one as
used for SQLServer 2000) , we get the same error. However, It is possible to
create other standard COM objects (like the SQLDMO objects), using the
sp_oacreate. So, it may be something particular to .net assemblies being
called (via the COM interop wrapper) from SQL Server 2005.|||You should really go another route. Having SQL Server execute code hosted by
CLR was never supported
though spOACreate nor xp_cmdshell. I'd consider re-writing that com object a
s a CLR stored procedure
and you are in a supported environment. Below is my general "canned" respons
e:
It is not supported for extended stored procedures or sp_OA procedures to ca
ll .NET code in CLR;
hosted within SQL Server's adress space..
See:
http://support.microsoft.com/defaul...kb;en-us;322884
Also, below is witnh permission from David Browne, explaining how you can ha
ve SQL Server execute
CLR code executing in its own process:
"
Short answer: Don't do it.
Calling managed code inside a stored procedure is not supported.
http://support.microsoft.com/defaul...kb;en-us;322884
At least not directly. You need some sort of unmanaged proxy to communicate
with your component running in another process.
For instance, http, or, drum roll, a COM+ Server Application.
This will cause COM+ to load an unmanaged proxy object in the SqlServer
process and will load the CLR into a COM+ surrogate process (dllhost.exe).
Which somebody here mentioned last week, and I just got around to testing.
It's all perfectly transparent to you, but you have to set up the COM+
server application.
Remember this is something different from .net remoting. With .NET remoting
you have a _managed_ proxy object in the local process, and so you load the
CLR in the local process as well as the remote process.
Anyway here's what I did:
I created this VB class
comTest.vb listing:
Imports System.Runtime.InteropServices
<ClassInterface(ClassInterfaceType.AutoDual),
ProgId("comTest.comTestClass")> _
Public Class comTest
Public Function Hello() As String
Return "hello"
End Function
End Class
build comTest.dll and registered it with
regasm /codebase comTest.dll /tlb:comTest.tlb
(complains that I haven't strong-named my assembly, which you should do.)
created an empty COM+ server application, set to run under a local
administrator account, and dragged comTest.dll into its components folder.
created an unmanaged host (vbscript will do), and invoked the component
using IDispach just like SQLServer.
test.vbs listing
Set d = CreateObject("comTest.comTestClass")
MsgBox d.Hello
Then I used the .net command line debugger cordbg.exe's 'pro' command to
list the processes hosting the CLR. And procexp.exe from
www.sysinternals.com to verify that the CLR's dll's were not loaded in my
unmanaged process. My unmanaged host did not load the CLR, although it
loaded "comsvcs.dll", and the CLR was loaded by the dllhost.exe process.
Then in sql I ran
declare @.object int
declare @.msg varchar(50)
declare @.rc int
declare @.hr int
declare @.source varchar(1000)
declare @.description varchar(1000)
exec @.rc = sp_oacreate 'comTest.comTestClass', @.object output
if @.rc <> 0
begin
EXEC @.hr = sp_OAGetErrorInfo @.object, @.source OUT, @.description OUT
print 'create failed ' + @.description
return
end
exec @.rc = sp_oamethod @.object, 'Hello', @.msg output
if @.rc <> 0
begin
EXEC @.hr = sp_OAGetErrorInfo @.object, @.source OUT, @.description OUT
print 'method failed ' + @.description
return
end
print 'return: ' + @.msg
exec @.rc = sp_oadestroy @.object
if @.rc <> 0
begin
EXEC @.hr = sp_OAGetErrorInfo @.object, @.source OUT, @.description OUT
print 'destroy failed ' + @.description
return
end
Ran fine, and still only one CLR loaded into dllhost.exe's process. So
think we can safely conclude that COM+ server applications do not violate
the prohibition against running managed code in SQLServer's process and
provide a convenient mechanism for interoperating with managed code from
TSQL.
David
"
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Ian" <Ian@.discussions.microsoft.com> wrote in message
news:EC73FFA6-3F3E-47EE-809E-18BF1D60A88E@.microsoft.com...
>I have a .Net 1.1 assembly (written using C# in VS2003). This assembly has
> the option COM Interop set to True. Once built, the VS2003 project solutio
n
> produces a .tlb file. A setup is produced (from within VS2003) that includ
es
> the dll and tlb files. These are installed on a PC (running on Windows
> 2000/2003 server/Windows XP Pro) that has SQL Server 2000 running on it (w
ith
> the latest SQL Server 2000 Service Pack). A trigger fired from one of the
> tables in our own database (within SQL Server 2000) makes the calls to the
> COM wrapped assembly.
> CREATE TRIGGER [UserProfile_Trigger1] ON [UserProfile]
> FOR INSERT, UPDATE,DELETE
> AS
> DECLARE @.hr int
> DECLARE @.factory int
> DECLARE @.xalert int
> DECLARE @.response int
> DECLARE @.errMsg varchar(8000)
> DECLARE @.success bit
> EXEC @.hr = sp_OACreate 'csSOAPClient2.CXalertsApiSoapClient', @.factory OUT
PUT
> select @.hr
> IF (@.hr <> 0 )
> BEGIN
> EXEC sp_displayoaerrorinfo @.factory , @.hr
> RETURN
> END
> EXEC @.hr = sp_OAMethod @.factory, 'getXalertsInstanceUsingSOAPDefaults',
> @.xalert OUTPUT, 'rmi://localhost:50001/com/xalert/server/api/XAlertsFactor
y',
> 'http://localhost:8080/axis/services/xalertsport'
> IF (@.hr <> 0 )
> BEGIN
> EXEC sp_displayoaerrorinfo @.factory , @.hr
> RETURN
> END
> EXEC @.hr = sp_OAMethod @.xalert, 'queueByID', @.response OUTPUT, 1, '',
> 'MyXalerts55_030506_ss', 1100
> IF (@.hr <> 0 )
> BEGIN
> EXEC sp_displayoaerrorinfo @.xalert , @.hr
> RETURN
> END
> EXEC @.hr = sp_OAGetProperty @.response, 'Success', @.success OUT
> IF (@.hr <> 0 )
> BEGIN
> EXEC sp_displayoaerrorinfo @.response , @.hr
> RETURN
> END
> IF (@.success = 0)
> BEGIN
> EXEC @.hr = sp_OAGetProperty @.response, 'ErrorText', @.errMsg OUT
> IF (@.hr <> 0 )
> BEGIN
> EXEC sp_displayoaerrorinfo @.response , @.hr
> RETURN
> END
> END
> EXEC @.hr = sp_OADestroy @.xalert
> EXEC @.hr = sp_OADestroy @.response
> EXEC @.hr = sp_OADestroy @.factory
>
> This works fine and we are able to create the objects and make the method
> calls on it.
> We have now taken that .Net 1.1 project and recompiled it in .Net 2.0 and
> VS2005, using the same settings as before. A new setup was created and
> installed on a PC running on Windows 2000 Server and has SQL Server 2005 S
P1
> installed. "CLR integration" and "xp_cmdshell" have been enabled. Master
> database and our own databse have been made "trustworthy". The assembly
> created above (with .net 2,.0) has been created within SQL Server, setting
> External_acesss (tried unsafe as well) permissions on it.
> We are using the same trigger as above and the same code within the trigge
r.
> The trigger fails on the sp_oacreate line with the following error.
> OLE Automation Error
> HRESULT: 0x80131700
> Source: ODSOLE EXtended Procedure
>
> We have tried to put more COM Wrapper around the generated tlb , but that
> has not worked - giving the same error. Using .net 1.1 assembly (same one
as
> used for SQLServer 2000) , we get the same error. However, It is possible
to
> create other standard COM objects (like the SQLDMO objects), using the
> sp_oacreate. So, it may be something particular to .net assemblies being
> called (via the COM interop wrapper) from SQL Server 2005.|||"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:e$J%23mTUmGHA.1896@.TK2MSFTNGP05.phx.gbl...
> You should really go another route. Having SQL Server execute code hosted
> by CLR was never supported though spOACreate nor xp_cmdshell. I'd consider
> re-writing that com object as a CLR stored procedure and you are in a
> supported environment. Below is my general "canned" response:
> It is not supported for extended stored procedures or sp_OA procedures to
> call .NET code in CLR; hosted within SQL Server's adress space..
> See:
> http://support.microsoft.com/defaul...kb;en-us;322884
> Also, below is witnh permission from David Browne, explaining how you can
> have SQL Server execute CLR code executing in its own process:
>
Thanks,
But if I understand the question, the OP has compiled and installed the
assembly in SQL CLR. If so, he just needs to issue write a CLR stored
procedure in .NET that implements the trigger logic. Accessing the assembly
the OLE Automation stored procedures is no longer necessary. The trigger
body just needs to invoke a CLR stored procedure.
David|||"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:e$J%23mTUmGHA.1896@.TK2MSFTNGP05.phx.gbl...
> You should really go another route. Having SQL Server execute code hosted
> by CLR was never supported though spOACreate nor xp_cmdshell. I'd consider
> re-writing that com object as a CLR stored procedure and you are in a
> supported environment. Below is my general "canned" response:
> It is not supported for extended stored procedures or sp_OA procedures to
> call .NET code in CLR; hosted within SQL Server's adress space..
> See:
> http://support.microsoft.com/defaul...kb;en-us;322884
> Also, below is witnh permission from David Browne, explaining how you can
> have SQL Server execute CLR code executing in its own process:
>
Thanks,
But if I understand the question, the OP has compiled and installed the
assembly in SQL CLR. If so, he just needs to issue write a CLR stored
procedure in .NET that implements the trigger logic. Accessing the assembly
the OLE Automation stored procedures is no longer necessary. The trigger
body just needs to invoke a CLR stored procedure.
David|||Yes, I fully agree. However, the first post indicates that this isn't what t
he OP had in mind. Or
perhaps the first post seemed a bit ambiguous on this:

> We are using the same trigger as above and the same code within the trigge
r.
> The trigger fails on the sp_oacreate line with the following error.
> OLE Automation Error
> HRESULT: 0x80131700
> Source: ODSOLE EXtended Procedure
Thanks for making that option explicit, though. :-)
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"David Browne" <davidbaxterbrowne no potted meat@.hotmail.com> wrote in messa
ge
news:%23Hf3w3dmGHA.4536@.TK2MSFTNGP04.phx.gbl...
> "Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote i
n message
> news:e$J%23mTUmGHA.1896@.TK2MSFTNGP05.phx.gbl...
> Thanks,
> But if I understand the question, the OP has compiled and installed the as
sembly in SQL CLR. If
> so, he just needs to issue write a CLR stored procedure in .NET that imple
ments the trigger logic.
> Accessing the assembly the OLE Automation stored procedures is no longer n
ecessary. The trigger
> body just needs to invoke a CLR stored procedure.
> David|||Yes, I fully agree. However, the first post indicates that this isn't what t
he OP had in mind. Or
perhaps the first post seemed a bit ambiguous on this:

> We are using the same trigger as above and the same code within the trigge
r.
> The trigger fails on the sp_oacreate line with the following error.
> OLE Automation Error
> HRESULT: 0x80131700
> Source: ODSOLE EXtended Procedure
Thanks for making that option explicit, though. :-)
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"David Browne" <davidbaxterbrowne no potted meat@.hotmail.com> wrote in messa
ge
news:%23Hf3w3dmGHA.4536@.TK2MSFTNGP04.phx.gbl...
> "Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote i
n message
> news:e$J%23mTUmGHA.1896@.TK2MSFTNGP05.phx.gbl...
> Thanks,
> But if I understand the question, the OP has compiled and installed the as
sembly in SQL CLR. If
> so, he just needs to issue write a CLR stored procedure in .NET that imple
ments the trigger logic.
> Accessing the assembly the OLE Automation stored procedures is no longer n
ecessary. The trigger
> body just needs to invoke a CLR stored procedure.
> David

Call to Analysis Services via SQL CLR?

I'm trying to query Analysis Services 2000/2005 from SQL Server 2005 without using a Linked Server or OPENQUERY. My thoughts were I could create a .NET assembly that accepts a server name, and mdx to execute, and return the data to SQL Server. Has anyone tried this or is this possible?Thats sure possible e.g. with the oledbconenction object, but you will have to keep in mind that this will the EXTERNAL access and therefore your permission set of the assembly has to be set to this level.

Jens K. Suessmeyer.

http://www.sqlserver2005.de

Saturday, February 25, 2012

Call a WCF service from SQL CLR sproc

It is possible to call WCF from SQL CLR, can I add a web reference or use the proxy created with svcutil ?hi check out this link

http://blogs.neudesic.com/blogs/shaun_collett/archive/2007/04/29/6050.aspx

Call a WCF service from SQL CLR sproc

It is possible to call WCF from SQL CLR, can I add a web reference or use the proxy created with svcutil ?hi check out this link

http://blogs.neudesic.com/blogs/shaun_collett/archive/2007/04/29/6050.aspx