Solved

Connection.Open fails

Posted on 2003-10-27
3
386 Views
Last Modified: 2010-04-16
Hi,

I am fairly new to programming in C#.  I am trying to connect to a database.  I keep getting an exception when trying to execute the connection.open method.  Any ideas?:


Unhandled Exception: System.Security.SecurityException: Request for the permission of type System.Data.SqlClient.SqlClientPermission, System.Data, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.
   at System.Security.CodeAccessSecurityEngine.CheckHelper(PermissionSet grantedSet, PermissionSet deniedSet, CodeAccessPermission demand, PermissionToken permToken)
   at System.Security.CodeAccessSecurityEngine.Check(PermissionToken permToken, CodeAccessPermission demand, StackCrawlMark& stackMark, Int32 checkFrames, Int32 unrestrictedOverride)
   at System.Security.CodeAccessSecurityEngine.Check(CodeAccessPermission cap, StackCrawlMark& stackMark)
   at System.Security.CodeAccessPermission.Demand()
   at System.Data.SqlClient.SqlConnectionString.Demand(SqlConnectionString constr)
   at System.Data.SqlClient.SqlConnection.Open()
   at BS.BST_Project.getAllProjectsFinancials()
   at BS.BST_Project.Main(String[] args)

The state of the failed permission was:
<IPermission class="System.Data.SqlClient.SqlClientPermission, System.Data, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
             version="1"
             AllowBlankPassword="False">
   <add ConnectionString="Data Source=XX.XX.XX.XXX;Initial Catalog=BST_DB;User Id=test;"
        KeyRestrictions=""
        KeyRestrictionBehavior="AllowOnly"/>
</IPermission>
0
Comment
Question by:aamir11
3 Comments
 

Expert Comment

by:paylett
ID: 9630821
It appears that your database requires a password, and you haven't supplied one. Check your connection string.
0
 
LVL 1

Accepted Solution

by:
aamir11 earned 0 total points
ID: 9633868
Actually I figured out the problem.  I was running the application from a mapped drive to a database on another server.  That was failing.  However if I ran the application from the same drive as sthe server was located on, it worked.  Not sure why but it did
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now