Ad

Sql Server Log In Failed For WPF C# Project

- 1 answer

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

Ad

Answer

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

Ad
source: stackoverflow.com
Ad