MrDave's (David Yack) WebLog

Sql2005 Managed Stored Proc Error

Ok – so I created a new class library project – I referenced sqlaccess.dll

I added my new class which looks like this :

namespace testsqlclr.SProcTest1
{
    public class GetIssueSummaryTable
    {
        [SqlProcedure]
        public static void GetIssues()
        {
            SqlPipe pipe = SqlContext.GetPipe();
            SqlCommand cmd = SqlContext.GetCommand();
            cmd.CommandText = "Select issueid,issuetitle from issue";
            SqlDataReader reader = cmd.ExecuteReader();
            pipe.Send(reader);
        }
    }

From SQL Studio in SQL 2005 I try this:

create assembly dytest1 from 'c:\testapp\testsqlclr\testsqlclr\bin\debug\testsqlclr.dll'

The result is :

Msg 6212, Level 16, State 1, Line 1
CREATE ASSEMBLY failed because method 'get_Value' on type 'testsqlclr.Properties.Settings'  in safe assembly 'testsqlclr' is storing to a static field. Storing to a static field is not allowed in safe assemblies.

Anyone else run into this and find a work around?

I was so excited to actually see it work!

Comments

David Yack said:

Update....Some times I hate the fact that I can't just wait for someone else to answer my questions!

In VS2005 there is a new project type called SQL Server Project - you can find it under the Visual C# / Database when you are adding a new project (Same thing under Visual Basic if that is your preference)

Apparently there's a difference between the Sql Project and a typical class library that causes the error I had above.

I guess I can sleep well tonight knowing that my simple managed stored proc worked!
# August 7, 2004 1:43 AM

Rushi Desai said:

I've faced this problem. My hack was to actually edit the .vsproj file by hand. It's a simple XML file which lists the files that are going to be built while compiling and linking the assembly. You can remove all the items that reference Properties/*.cs because they contain static fields which are disallowed in safe SQLCLR assemblies. When you build, your assembly will no longer contain the visual studio generated classes and SQLCLR will be happy with the assembly.
# August 7, 2004 3:56 AM

TrackBack said:

VS2005でそのまま作ったプロジェクトはインテグレーション出来ない。

そのままですが、Visual Studio 2005 Beta1で作っただけのクラスライブラリをいきなりSQL Server 2005 Beta2にはCreate Assmbly出来ないみたいです。

# October 25, 2004 1:32 PM

TrackBack said:

VS2005でそのまま作ったプロジェクトはインテグレーション出来ない。

そのままですが、Visual Studio 2005 Beta1で作っただけのクラスライブラリをいきなりSQL Server 2005 Beta2にはCreate Assmbly出来ないみたいです。

# October 25, 2004 1:40 PM

Suenthen said:

I should notify my pal about this.

# December 15, 2009 12:51 PM

Acinnina said:

мне кажется: восхитительно!!  а82ч

# February 24, 2010 8:14 AM

X-tube Pee Peeking said:

yoo. bookmarked thread :))

# March 3, 2010 9:33 PM

ipad app icons said:

Nurture passes nature.

-----------------------------------

# December 18, 2010 7:55 PM

best ipad accessories said:

-----------------------------------------------------------

"Nice post! GA can also be my greatest earning. Nonetheless, it is not a considerably.thanks !! very useful submit!"

# January 3, 2011 4:18 PM

ipad accessories said:

-----------------------------------------------------------

I am speechless. This can be a wonderful website and very engaging too. Excellent operate! That is not actually much coming from an beginner author like me, but it is all I could consider right after enjoying your posts. Wonderful grammar and vocabulary. Not like other blogs. You seriously know what you're talking about very. So very much which you created me need to examine much more. Your weblog has become a stepping stone for me, my buddy. Give thanks to you for your articulate journey. I truly loved the 27 posts that I've go through so significantly.

# January 8, 2011 1:49 PM

hd video camera reviews said:

amazing stuff thanx

--------------------------------------------------------------------    

Celtic Languages and Literatures

# January 17, 2011 2:33 PM

Sid Dehl said:

I'm not that considerably of a on the internet reader to be honest but your websites really nice, keep it up! I'll go ahead and bookmark your website to come back later.

# June 29, 2011 9:05 PM

Charlotte Beauchesne said:

Superb post. I basically stumbled upon your weblog and wanted to say that we have seriously enjoyed reading by means of your web site posts. Any way I'll be registering to your feed and that i hope you post again soon.

# July 4, 2011 4:39 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)