Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old November 14th, 2008, 09:28 AM
Authorized User
Join Date: Nov 2008
Posts: 21
Thanks: 3
Thanked 0 Times in 0 Posts
Send a message via MSN to MonkeyMan666
Default SQL Server Connection


I am new to C# (and the .NET framework).

I am trying to connect to a database on SQL Server 2005. It is creating the connection ok but when I try and access any data I keep getting errors like:

System.Security.SecurityException: Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
   at System.Security.CodeAccessSecurityEngine.Check(Obj ect demand, StackCrawlMark& stackMark, Boolean isPermSet)
   at System.Security.PermissionSet.Demand()
   at System.Data.Common.DbConnectionOptions.DemandPermi ssion()
   at System.Data.SqlClient.SqlConnection.PermissionDema nd()
   at System.Data.SqlClient.SqlConnectionFactory.Permiss ionDemand(DbConnection outerConnection)
   at System.Data.ProviderBase.DbConnectionClosed.OpenCo nnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
   at System.Data.SqlClient.SqlConnection.Open()
   at ProjectReportingReports.AllReportFilterForm.AllRep ortFilterForm_Load(Object sender, EventArgs e)
   at System.Windows.Forms.Form.OnLoad(EventArgs e)
   at System.Windows.Forms.Form.OnCreateControl()
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.WmShowWindow(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Mes sage& m)
   at System.Windows.Forms.ContainerControl.WndProc(Mess age& m)
   at System.Windows.Forms.Form.WmShowWindow(Message& m)
   at System.Windows.Forms.Form.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.O nMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.W ndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
The action that failed was:
The type of the first permission that failed was:
The Zone of the assembly that failed was:

I have tried adding my application to the list in the .NET security configuration tool, I have tried asserting SQL Data Client permissions before the connections are even created. I am finding myself staring at the screen lost and getting stressed out. Can anyone help me with this?



Old November 14th, 2008, 09:38 AM
samjudson's Avatar
Friend of Wrox
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts

I'm only guessing, but are you running the application from a network drive?

Try copying the executable to the local hard drive.

You can fix this by installing .Net 3.5 sp1 as well.

/- Sam Judson : Wrox Technical Editor -/
The Following User Says Thank You to samjudson For This Useful Post:
MonkeyMan666 (December 17th, 2008)
Old November 14th, 2008, 10:44 AM
Authorized User
Join Date: Nov 2008
Posts: 21
Thanks: 3
Thanked 0 Times in 0 Posts
Send a message via MSN to MonkeyMan666

Yes I was running it on a network drive.

It works fine when I run it from the machine local drive.

Many Thanks :)


Similar Threads
Thread Thread Starter Forum Replies Last Post
Connection to SQL Server brijxp ADO.NET 1 November 18th, 2006 08:34 AM
connection string for sql server rj1406 ASP.NET 1.0 and 1.1 Basics 6 September 16th, 2004 02:49 PM
Sql server connection failed AcidHell2 All Other Wrox Books 0 February 26th, 2004 01:57 PM
SQL Server Connection mpeterson Classic ASP Databases 1 July 8th, 2003 09:50 PM
Connection with sql server arshad mahmood VB Databases Basics 1 June 19th, 2003 10:53 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.