Click here to Skip to main content
15,914,111 members
Home / Discussions / C#
   

C#

 
GeneralRe: ListView columns not displayed Pin
Ravi Bhavnani14-Jan-06 13:24
professionalRavi Bhavnani14-Jan-06 13:24 
QuestionNeed help with a Windows Service Pin
Nathan R14-Jan-06 9:13
Nathan R14-Jan-06 9:13 
AnswerRe: Need help with a Windows Service Pin
Nathan R16-Jan-06 9:48
Nathan R16-Jan-06 9:48 
GeneralRe: Need help with a Windows Service Pin
BlackDice2-Feb-06 11:33
BlackDice2-Feb-06 11:33 
QuestionWrite to a text file Pin
aPerfectCircle14-Jan-06 8:43
aPerfectCircle14-Jan-06 8:43 
AnswerRe: Write to a text file Pin
User 665814-Jan-06 8:59
User 665814-Jan-06 8:59 
QuestionRemoting with localizable resources Pin
machocr14-Jan-06 8:07
machocr14-Jan-06 8:07 
QuestionSystem.Security.SecurityException Pin
OMalleyW14-Jan-06 5:23
OMalleyW14-Jan-06 5:23 
Hello,
Ok so I just figured out how to create an assembly with VS 2005 and SQL 2005 Express.

So I wanted to see if I could create a little routing that connected to my sqlserver, hit a stored procedure and returned the results to the assemply. The results would be printed out when the assembly was executed.

Here is the code for the CS file
<br />
<br />
using System;<br />
using System.Collections.Generic;<br />
using System.Text;<br />
using System.Data.SqlTypes;<br />
using System.Data.SqlClient;<br />
using Microsoft.SqlServer.Server;<br />
<br />
<br />
public class CountForMe<br />
{<br />
    private System.Data.SqlClient.SqlConnection ProductionConnection;<br />
    private System.Data.SqlClient.SqlCommand spListTypeCodes;<br />
<br />
<br />
    [Microsoft.SqlServer.Server.SqlProcedure]<br />
    public static void HereWeBe()<br />
    {<br />
        /***<br />
         * this is the entry point for the stored procedure<br />
         * second attempt ta this to see what we can do<br />
         **/<br />
        // in order to call a nonstatic class from within a static class<br />
        // you must create the following reference to the class<br />
        // reference: <br />
        // ms-help://MS.VSExpressCC.v80/MS.NETFramework.v20.en/dv_cscomp/html/3ff67f11-bdf9-436b-bc0c-4fa3cd1925a6.htm<br />
        CountForMe cfm = new CountForMe();<br />
        cfm.GetData();<br />
        cfm = null;<br />
        //<br />
    }<br />
    private void GetData()<br />
    {<br />
        // initialize connection string<br />
        ProductionConnection = new System.Data.SqlClient.SqlConnection();<br />
        spListTypeCodes = new System.Data.SqlClient.SqlCommand();<br />
        //<br />
        ProductionConnection.ConnectionString = "{TAKEN OUT FOR SECURITY}";<br />
        // setup stored procedure<br />
        spListTypeCodes.CommandText = "dbo.[spListTypeCodes]";<br />
        spListTypeCodes.CommandType = System.Data.CommandType.StoredProcedure;<br />
        spListTypeCodes.Connection = ProductionConnection;<br />
        spListTypeCodes.Parameters.Add(new System.Data.SqlClient.SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, false, ((System.Byte)(0)), ((System.Byte)(0)), "", System.Data.DataRowVersion.Current, null));<br />
        //<br />
        //<br />
        ProductionConnection.Open();<br />
        SqlDataReader myReader = spListTypeCodes.ExecuteReader();<br />
        if (myReader.HasRows)<br />
        {<br />
            string message = "";<br />
            // setup message to print to screen<br />
            message = "Type Code: " + myReader["TypeCode"].ToString() +<br />
                " Type Description: " + myReader["TypeDescription"].ToString() +<br />
                " Type Code deleted: " + myReader["TypeCodeDeleted"].ToString();<br />
            // now print message to list<br />
            SqlContext.Pipe.Send(message);<br />
        }<br />
        myReader.Close();<br />
        myReader = null;<br />
        ProductionConnection.Close();<br />
    }<br />
<br />
}<br />


When I run the procedure here is what I get

<br />
Msg 6522, Level 16, State 1, Procedure spSecondAttempt, Line 0<br />
A .NET Framework error occurred during execution of user defined routine or aggregate 'spSecondAttempt': <br />
System.Security.SecurityException: Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.<br />
System.Security.SecurityException: <br />
   at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)<br />
   at System.Security.PermissionSet.Demand()<br />
   at System.Data.Common.DbConnectionOptions.DemandPermission()<br />
   at System.Data.SqlClient.SqlConnection.PermissionDemand()<br />
   at System.Data.SqlClient.SqlConnectionFactory.PermissionDemand(DbConnection outerConnection)<br />
   at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)<br />
   at System.Data.SqlClient.SqlConnection.Open()<br />
   at CountForMe.GetData()<br />
   at CountForMe.HereWeBe()<br />


So I checked the 2.0 snap-in tool to make sure that my assembly is running with the correct permission set.
All looked good, in the Machine zone my assembly had full trust so I am guessing that means it has permission to do what ever it wants...

any help would be great. Do I maybe have to make the SQLAgent account a member of the Administrators group?


Thanks,
Will

I hate users. Not all of them, just the ones who talk.CP member: Al Einstien
QuestionRe: System.Security.SecurityException Pin
shopi3014-Jan-06 12:31
shopi3014-Jan-06 12:31 
AnswerRe: System.Security.SecurityException Pin
OMalleyW14-Jan-06 14:14
OMalleyW14-Jan-06 14:14 
QuestionHow insert controlls inide a listbox Pin
Sasuko14-Jan-06 4:23
Sasuko14-Jan-06 4:23 
AnswerRe: How insert controlls inide a listbox Pin
rabih_kai14-Jan-06 5:29
rabih_kai14-Jan-06 5:29 
Questionweb deployment set up project in .net 2005 Pin
cppdotnet14-Jan-06 1:23
cppdotnet14-Jan-06 1:23 
QuestionDrill down crystal reports in C# Pin
idreesbadshah14-Jan-06 1:03
idreesbadshah14-Jan-06 1:03 
QuestionHow can I get the contents of a given URL and edit it while displaying? Pin
sachu_vidya14-Jan-06 0:02
sachu_vidya14-Jan-06 0:02 
AnswerRe: How can I get the contents of a given URL and edit it while displaying? Pin
Mark Shehan14-Jan-06 13:50
Mark Shehan14-Jan-06 13:50 
GeneralRe: How can I get the contents of a given URL and edit it while displaying? Pin
sachu_vidya16-Jan-06 20:47
sachu_vidya16-Jan-06 20:47 
Questionhow do I implement scrolling? Pin
mihai_152913-Jan-06 21:59
mihai_152913-Jan-06 21:59 
AnswerRe: how do I implement scrolling? Pin
Robert Rohde13-Jan-06 22:20
Robert Rohde13-Jan-06 22:20 
GeneralRe: how do I implement scrolling? Pin
mihai_152913-Jan-06 22:46
mihai_152913-Jan-06 22:46 
GeneralRe: how do I implement scrolling? Pin
Curtis Schlak.14-Jan-06 2:48
Curtis Schlak.14-Jan-06 2:48 
Questionabout the listview Pin
abstarsss13-Jan-06 21:14
abstarsss13-Jan-06 21:14 
AnswerRe: about the listview Pin
mav.northwind13-Jan-06 21:51
mav.northwind13-Jan-06 21:51 
GeneralRe: about the listview Pin
abstarsss14-Jan-06 8:24
abstarsss14-Jan-06 8:24 
QuestionEmail issue Pin
damar1r13-Jan-06 19:49
damar1r13-Jan-06 19:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.