Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 406
  • Last Modified:

Connection.Open fails

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
aamir11
Asked:
aamir11
1 Solution
 
paylettCommented:
It appears that your database requires a password, and you haven't supplied one. Check your connection string.
0
 
aamir11Author Commented:
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now