Link to home
Start Free TrialLog in
Avatar of ovule
ovule

asked on

SQL Server 2005 Assembly WebPermission Issue

I have an assembly which reads an XML file from the Internet, parses it and updates a MS SQL Server 2005 database.  This works perfectly if run standalone.

My problems arise after I register this assembly with SQL Server and then execute a call to one of its methods through some CLR stored procedure.  The exception I am receiving is:

Msg 6522, Level 16, State 1, Procedure UpdateStarter, Line 0
A .NET Framework error occurred during execution of user defined routine or aggregate 'UpdateStarter':
System.Security.SecurityException: Request for the permission of type 'System.Net.WebPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
System.Security.SecurityException:
   at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
   at System.Security.CodeAccessPermission.Demand()
   at System.Net.HttpWebRequest..ctor(Uri uri, ServicePoint servicePoint)
   at System.Net.HttpRequestCreator.Create(Uri Uri)
   at System.Net.WebRequest.Create(Uri requestUri, Boolean useUriBase)
   at System.Net.WebRequest.Create(Uri requestUri)
   at System.Xml.XmlDownloadManager.GetNonFileStream(Uri uri, ICredentials credentials)
   at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials)
   at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn)
   at System.Xml.XmlTextReaderImpl.OpenUrlDelegate(Object xmlResolver)
   at System.Threading.CompressedStack.runTryCode(Object userData)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
   at System.Threading.CompressedStack.Run(CompressedStack compressedStack, ContextCallback callback, Object state)
   at System.Xml.XmlTextReaderImpl.OpenUrl()
   at System.Xml.XmlTextReaderImpl.Read()
   at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
   at System.Xml.XmlDocument.Load(XmlReader reader)
   at System.Xml.XmlDocument.Load(String filename)
  ...

I realise this is due to lack of permissions for connecting to the Internet, however do not know how to grant SQL Server permissions to do this, or do something else with the assembly to make it appear safe.

Your help is very appreciated.
ASKER CERTIFIED SOLUTION
Avatar of Adrian Pop
Adrian Pop
Flag of Sweden image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ovule
ovule

ASKER

Thanks adrpo!

Before posting this I tried the following, with both EXTERNAL_ACCESS and UNSAFE permissions through Management Studio - I didn't realise you had to do it through VS

CREATE ASSEMBLY MyAssembly
from 'M:\MyPath\MyAssembly.dll'
WITH PERMISSION_SET = EXTERNAL_ACCESS