locked
Vague error message in a vb.net windows application concerning System.Data.SqlClient.SqlClientPermission with the Intranet RRS feed

  • Question

  • Hello all,
    I am working on a windows application in vb.net 2005 and it needs to connect to the SQL Server database.  In this example I testing if the connection is able to open properly:

    Imports

    System
    Imports System.Data
    Imports System.Data.SqlClient

    Module Module1

     

    Sub Main()
    Dim connString As String = "Data Source=XXXXXX;Initial Catalog=XXXXXX;Persist Security Info=True;User ID=XXXXX;"
    Dim conn As SqlConnection = New SqlConnection(connString)

     

    Try
    conn.Open()
    msgbox(
    "Connection opened.")
    Catch ex As Exception
    Console.WriteLine(
    "Error write here: " & ex.ToString)
    Finally
    conn.Close()
    msgbox(
    "Connection closed")
    End Try
    End Sub


    When I debugged it, I get the following error message:
    Error: 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.
       at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
       at System.Security.PermissionSet.Demand()
       at System.Data.Common.DbConnectionOptions.DemandPermission()
       at System.Data.SqlClient.SqlConnection.PermissionDemand()
       at System.Data.SqlClient.SqlConnectionFactory.PermissionDemand(DbConnection outerConnection)
       at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
       at System.Data.SqlClient.SqlConnection.Open()
       at Chapter05.Module1.Main()
    The action that failed was:
    Demand
    The type of the first permission that failed was:
    System.Data.SqlClient.SqlClientPermission
    The Zone of the assembly that failed was:
    Intranet

    Is it something dealing with the permissions set with the database server or something?  I am new at .NET programming and I have been spinning my wheels on this for the past couple of days and I am at a loss.  From what I research, this error should only occur if I was creating a web program, but I am not.  It is a windows application.  Any suggestions and thanks in advance.

    Thursday, June 4, 2009 9:12 PM

Answers

  • Never mind.  I figured out the problem was.  I was running the application from a server, not from my local machine. The problem is that the server does not have permissions set up for access the database, if that makes sense.  So I copied the code and saved it on my machine.  It works now.  Thanks to everyone for their help.
    Monday, June 8, 2009 3:19 PM

All replies