Can't Get Enough RSS 2.0
 Saturday, December 22, 2007

I needed to create a CLR function to generate a report and uses ZedGraph to make a graph and save it on the disk.

I used VS 2005 to make the CLR function, but when try to add a reference to the project, all I see is few of the .Net assemblies, and there is no `Browse` button to add assemblies from the disk.

 

I did some google as usual and found this on Sql Server's Book Online:

Unsupported Libraries

Unsupported libraries can still be called from your managed stored procedures, triggers, user-defined functions, user-defined types, and user-defined aggregates. The unsupported library must first be registered in the SQL Server database, using the CREATE ASSEMBLY statement, before it can be used in your code. Any unsupported library that is registered and run on the server should be reviewed and tested for security and reliability.

And that solved the problem...

First, I'm not sure what Permission_Set ZedGrpah needs, so I'm going to mark the database as TrustWorthy so I can give the assembly an unsafe Permission_Set.

Use Master

Go

Alter Database Test Set TrustWorthy On

Go

Use Test

Go

Then when I added the ZedGraph I got an error message:

Create Assembly [ZedGraph]

From 'C:\ZedGraph\ZedGraph.dll'

With Permission_Set=Unsafe

 

Msg 10301, Level 16, State 1, Line 1

Assembly 'ZedGraph' references assembly 'system.windows.forms, version=2.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089.', which is not present in the current database. SQL Server attempted to locate and automatically load the referenced assembly from the same location where referring assembly came from, but that operation has failed (reason: 2(The system cannot find the file specified.)). Please load the referenced assembly into the current database and retry your request.

So I did as it says, I added the System.Windows.Forms first

Create Assembly [System.Windows.Forms]

From 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll'

With Permission_Set=Unsafe

 

I noticed on the object explorer that the System.Windows.Forms was added with its refereces

 

Now add the ZedGraph

Create Assembly [ZedGraph]

From 'C:\ZedGraph\ZedGraph.dll'

With Permission_Set=Unsafe

 

Now back to VS 2005

 

 

And everything goes well.

 

Important: Always add the unsupported assemblies from a query window, using CREATE ASSEMBLY command, do not add them using the Object Explorer, I tried it and it always gives error.

 

Saturday, December 22, 2007 4:58:45 AM UTC  #    Comments [0] -
C# | SQL Server
Name
E-mail
Home page

Comment (Some html is allowed: a@href@title, strike) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview
Navigation
Categories
Archive
<September 2010>
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2010
Ghazi Sarhan
Sign In
Statistics
Total Posts: 13
This Year: 0
This Month: 0
This Week: 0
Comments: 4
Themes
Pick a theme:
All Content © 2010, Ghazi Sarhan
DasBlog theme 'Business' created by Christoph De Baene (delarou)