2

The TimeZoneInfo class has a Host Protection Attribute of MayLeakOnAbort.

This seems to prevent me accessing it from the SQL Server CLR. But is there a workaround?

user74207
  • 251
  • 2
  • 7
  • OP says he created the new question to focus the responses better: http://stackoverflow.com/questions/614600/access-timezoneinfo-from-sql-2005-server/643607#643607 . @papillonuk Consider editing your original question instead. – Michael Ratanapintha Mar 13 '09 at 17:14
  • Hi Michael/Ken, yes sorry for the cheeky resurrection of the old question. Hope my self-answer explains my reasons. Didn't want to re-edit the previous question too much as it would make the comments from other users into non-sequiturs. It was my 1st question on here and I think I learned a lesson! – user74207 Mar 13 '09 at 20:11
  • The other question is a better place to discuss this. It gives enough detail as to why the author needs to use TZI inside of SQL Server. The correct answer to this question in its current form is "Don't do that. Pass in what you need." The answer to the original question might actually involve calling TZI from SQL Server. – Jason Kester Mar 18 '10 at 22:09

2 Answers2

2

Yeah sure. You encapsulate it in another .NET class and then reference from your .NET assembly in SQL Server. Then you complete disable the security in your SQL Server database so you can run the second class.

If that does not work, you can create a COM wrapper and then an Interop wrapper and still destroy security in SQL Server to run the thing.

Now, if security actually matters to you, you can create a WCF service that wraps the bits you need and use it as a service from your SQL code. It is a bit of latency and cannot work against objects in SQL Server, per se, but it is cleaner.

Sorry for the snarky sounding answer, but I am in a strange mood right now. :-)

Gregory A Beamer
  • 16,870
  • 3
  • 25
  • 32
0

Deploy your CLR procedure as Unsafe:

Right click project in Visual Studio > Properties > Database tab > Permission Level

Then, to deploy it, you need to configure the database so it will accept unsafe assemblies. Two options:

the database owner (DBO) has UNSAFE ASSEMBLY permission and the database has the TRUSTWORTHY database property on;

...or the assembly is signed with a certificate or an asymmetric key that has a corresponding login with UNSAFE ASSEMBLY permission.

frankadelic
  • 20,543
  • 37
  • 111
  • 164
  • 1
    Snarky comment: You don't compile the assembly as unsafe, that checkbox will instruct the deployer to deploy it as unsafe. Doesn't affect compilation, though – erikkallen Mar 18 '10 at 22:06