Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Request for the permission of type System.Data.Sql

Author  Topic 

shifis
Posting Yak Master

157 Posts

Posted - 2005-05-11 : 15:10:08
Hi!
I am using VB.Net and SQL Server 2000, when I try to open a connection with SQL Server I receive the next error:

An unhandled exception of type 'System.Security.SecurityException' occurred in mscorlib.dll

Additional information: Request for the permission of type System.Data.SqlClient.SqlClientPermission, System.Data, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.



This is the code that I have:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cnSQL As New SqlClient.SqlConnection
Dim cmdSQL As New SqlClient.SqlCommand
Dim paramSQL1 As New SqlClient.SqlParameter("@USER_NUM", SqlDbType.SmallInt)
Dim paramSQL2 As New SqlClient.SqlParameter("@PASSWORD", SqlDbType.VarChar)
Dim datRead As SqlClient.SqlDataReader
Try
cnSQL.ConnectionString = "user id=sa;data source=SQL_SMART;persist security info=False;initial catalog=Northwind"
cnSQL.Open()
With paramSQL1
.Direction = ParameterDirection.Input
.Value = 1

End With
With paramSQL2
.Direction = ParameterDirection.Input
.Value = "VERDE"

End With

With cmdSQL
.Connection = cnSQL
.CommandType = CommandType.StoredProcedure
.CommandText = "SP_LOGINUSUARIO"
.Parameters.Add(paramSQL1)
.Parameters.Add(paramSQL2)
End With

datRead = cmdSQL.ExecuteReader
Do While datRead.Read
MessageBox.Show(datRead(0).ToString)


Loop
datRead.Close()
Catch ex As Exception
MsgBox("Can't load Web page" & vbCrLf & ex.Message)

MsgBox(ex.ToString) ' Show friendly error message.
Finally
Beep() ' Beep after error processing.
End Try

End Sub

and the error happens here: cnSQL.Open()

I am accessing a SQL Server Data Base not installed in my computer.

The proyect that I am using is save on a network drive, I try the same code in a project that I save on my hard disk and it didn't send me any error, but I have to save on a network drive because I am not the only one that will use the project.
Thank for you time!!

shifis
Posting Yak Master

157 Posts

Posted - 2005-05-13 : 18:28:41
Solution:
From Start+Programs+ Microsoft Visual Studio .NET 2003+ Visual Studio .NET 2003 Command Prompt, execute the next:

1. Start mscorcfg.msc.
(You have to wait to be appear a new window)
2. Expand the Runtime Security Policy node, the Machine node, the Code Groups node, the All_Code node, and then highlight the LocalIntranet_Zone node.
3. In the right pane select Add a Child Code Group.
4. Choose Create a new Codegroup and enter a name for the code group, then click Next.
5. Choose a Condition Type of URL, then enter the UNC path to the share location of your project, using the format file///\\servername\sharename\* where \\servername\sharename is the name of the share. Click Next.

Note Make sure to add the asterisk at the end of the path.

(here I have some troubles, so let me tell you that if you don't add file/// at the begining and you only type the other information:
\\CORPORATIVO_3\DATOS\archivos\sistemas\castro\pos\prjpos\*

you obtain something like this:
file://CORPORATIVO_3/DATOS/archivos/sistemas/castro/pos/prjpos/*

servername=//CORPORATIVO_3/DATOS
sharename=archivos/sistemas/castro/pos/prjpos/*


)


6. Choose Use Existing Permission Set of FullTrust, then click Next.
7. Click Finish.
8. Restart Visual Studio.
Go to Top of Page
   

- Advertisement -