0

I need advice on the best way of doing this.

Currently I have a clr procedure in MSSQL 2012 that bulk inserts a delimited data file into a temporary table it creates, then processes all the rows via various text/math logic into live data table.

Once its done, i would like to get rid of the table it created. DROP TABLE xxx is where I get the following error.

Msg 6522, Level 16, State 1, Procedure SyncAgents, Line 0
A .NET Framework error occurred during execution of user-defined routine or aggregate "SyncAgents": 
System.Security.HostProtectionException: Attempted to perform an operation that was forbidden by the CLR host.

The protected resources (only available with full trust) were: All
The demanded resources were: ExternalThreading

System.Security.HostProtectionException: 
   at StoredProcedures.SyncAgents()
.

Basically means it needs to be UNSAFE. Which is something I would like to avoid. So the question is:

What is the best way of dropping this table after I am done with it? Should it be a scheduled task? Is there some kind of clever trigger that can be set up to do it?

I am thinking of creating a scheduled procedure that looks in the queue (simple varchar/bit with tablename/isprocessed table) and then executes drops based on that queue.

Am I thinking of the problem wrong from the outset?

Would appreciate your suggestions.

4

1 回答 1

0

If you use a proper temporary table (ie: one prefixed with a #) rather than a user table, you'll have the required permissions.

于 2012-08-20T19:28:06.367 回答