views:

18

answers:

2

When I'm trying to execute a clr sproc (Still in C# IDE for this) I have permission errors. The error is " Request for the permission of type 'System.Data.SqlClient.SqlClientPermission,... failed", I've looked around online and it seems to throw back to IIS settings (I'm not using IIS nor am I using a website so these solutions don't apply to me), now I tried two separate connection strings for this as well (context connection = true, as well the way I usually do it which is the huge long one that says it's a trusted connection and the database name) but both return the same permissions failed.

Any help would be greatly appreciated

A: 

Speak with your DBA regarding your users database permissions. This is probably not an issue in code.

Jimmy Hoffa
It's a local database on my machine. Copied from the development environment for the specific purposes of testing. I have another program that can properly do SQL commands to and from it, locally as well.
CSharpProgrammer
@CSharpProgrammer: Can that other program successfully execute the stored procedure you're trying to?
Jimmy Hoffa
No because I'm making it as a CLR Sproc, and as far as I know, I can't make it unless it properly goes through the build
CSharpProgrammer
@CSharpProgrammer: Have you stepped into the code and made sure in the actual connection object the credentials in use are the same as when you run stuff in management studio? Also there are special permissions specifically for running CLR Sprocs which your user may not have.
Jimmy Hoffa
The credentials are the same between my program that can connect to the database without issue but I will double check on the management studio side. Likewise, I will have to look into the permissions for running CLR Sprocs if that is the case, I have enabled them but I don't know about the permissions part.Thanks for the help, I'll have to take a look at these issues Monday morning
CSharpProgrammer
A: 

Is CLR enabled within your instance of SQL server?

You can enable it by running the following SQL statement against your SQL server:

sp_configure 'clr enabled', 1 GO

Once this is ran, the assembly needs to be registered to SQL:

CREATE ASSEMBLY ASSEMBLYNAME FROM 'Full path to assembly' --e.g. C:\sproc.dll WITH Permission_SET = SAFE GO

Create the stored procedure like this (if you haven't already) CREATE PROC clrsp_InsertEmployee (
Comma delimited parameters ) --Parameters example @City VARCHAR(25), @state VARCHAR(2)
AS EXTERNAL NAME AssemblyName.StoredProcedures.Function Go

Let me know if this helps. Other than that, you may need to setup permissions to the tables based on the user that you are utilizing to access SQL.

amahoski
Well I did the first assembly statement and it said there was already a stored procedure was identical to an already registered name so I found that (My mistake for not seeing it sooner) and when I try to run it it gives me the security error still. Since it's already showing, I shouldn't need to do the create, right?Thanks for your help and anymore you can provide
CSharpProgrammer