Friday, March 9, 2012

method call works from .Net form and not from SQL CLR - EnterpriseLibrary used

Hello

I created a wrapper class for a function, and exposed it through CLR. However, if I call this function form SQL it blows up but if I call directly from a test Windows Form the call works fine.

The blow up is related to EnterpriseLibrary.Data, where my Queue class uses that library to do all data access call ops

Here's my wrapper class:

namespace inlineCLRsql{

public static class Wrapper{

public static void CallQueueEntry(int queueId, int deskNo, int missed){

inLineLib.Queue oQueue;

inLineLib.QueueEntry oQueueEntry;

oQueue = new inLineLib.Queue(queueId);

oQueueEntry = oQueue.callQueueEntry(deskNo, false);

Microsoft.SqlServer.Server.SqlContext.Pipe.Send(oQueueEntry.queueNum.ToString());

}

}

And this is my CLR SQL creation code:

CREATE PROC sp_CallQueueEntry

@.queueId int,

@.deskNo int,

@.missed int

AS

EXTERNAL NAME inLineLib.[inlineCLRsql.Wrapper].CallQueueEntry

GO

sp_CallQueueEntry 4,2,0

Here is what I get as a result

System.NullReferenceException: Object reference not set to an instance of an object.

System.NullReferenceException:

at Microsoft.Practices.EnterpriseLibrary.Data.DatabaseConfigurationView.get_DefaultName()

at Microsoft.Practices.EnterpriseLibrary.Data.DatabaseMapper.MapName(String name, IConfigurationSource configSource)

at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfigurationNameMappingStrategy.BuildUp(IBuilderContext context, Type t, Object existing, String id)

at Microsoft.Practices.ObjectBuilder.BuilderBase`1.DoBuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies)

at Microsoft.Practices.ObjectBuilder.BuilderBase`1.BuildUp(IReadWriteLocator locator, Type typeToBuild, String idToBuild, Object existing, PolicyList[] transientPolicies)

at Microsoft.Practices.ObjectBuilder.BuilderBase`1.BuildUp[TTypeToBuild](IReadWriteLocator locator, String idToBuild, Object existing, PolicyList[] transientPolicies)

at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.EnterpriseLibraryFactory.BuildUp[T](IReadWriteLocator locator, IConfigurationSource configurationSource)

at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.EnterpriseLibraryFactory.BuildUp[T](IConfigurationSource configurationSource)

at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.NameTypeFactoryBase`1.CreateDefault()

at Microsoft.Practices.EnterpriseLibrary.Data.DatabaseFactory.CreateDatabase()

at inLineLib.Queue.getNextQueueEntry(Int32 servedBy)

at inLineLib.Queue.callQueueEntry(Int32 servedBy, Boolean callMissed)

at inlineCLRsql.Wrapper.CallQueueEntry(Int32 queueId, Int32 deskNo, Int32 missed)

What can I do to fix this?

Cheers

M

This is almost a total guess - I've never used EntLib. However, I found some one else hit this issue when EntLib was not able to find the database in the application config file: http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_21833370.html

This is likely to be the same problem you're facing. I believe you can solve this by running the Enterprise Library Config tool and specify your config file as sqlservr.exe.config in the same directory as sqlservr.exe. Or you can try copying and renaming the config file your Windows Form app is using.

Hope this works.

Steven

No comments:

Post a Comment