views:

396

answers:

2

i have created a installed sql server 2008 on my win xp box and i am developing my wpf web app on my laptop. when i try to create a connection with code i get a security error, i try connecting with the user/password combo with managment studio on my laptop with no issue. This is the code i have, at con.Open() i get the error message tha i have posted upder the code.

sql.SqlConnectionStringBuilder csb = new System.Data.SqlClient.SqlConnectionStringBuilder();
csb.DataSource = "mkitt.com";
csb.UserID = "user";
csb.Password = "password";
csb.InitialCatalog = "Investix";
sql.SqlConnection con = new sql.SqlConnection(csb.ConnectionString);
con.Open();



System.Security.SecurityException was unhandled by user code
  Message="Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."
  Source="mscorlib"
  StackTrace:
       at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)

... i cut of the rest of the stack trace...

I have never encountered this error before not sure the cause/solution does anyone know the issue?

Thanks in advance for the help

Marios

+1  A: 

This is usually a trust related issue. You need to set the security properties in your WPF project to use "Full Trust".

Jose Basilio
+1  A: 

That is a "code access security policy" (caspol) issue - i.e. your WPF app isn't running in full trust, and doesn't have the cited permission.

If you are deploying with ClickOnce, you can allocate which permissions your app should request on the Security tab (project properties). You can also request full trust if needed.

Marc Gravell