0
votes

I write this query in a crm plugin but i get this error

I create this view (vwPayrollEmployees) in crm database

Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed

SqlConnection myConnection = new SqlConnection("Data Source=........;Initial Catalog=......;Persist Security Info=True;User ID=sa;Password=.......;");
SqlCommand myCommand = new SqlCommand("[Depart]FROM [mbm_MSCRM].[dbo].[vwPayrollEmployees] WHERE [mbmhr_EmployeeNbr] =@EmpNbr", myConnection);
myCommand.Parameters.Add("@EmpNbr", empnbr);

myCommand.Connection = myConnection;
myConnection.Open();
SqlDataReader myReader = myCommand.ExecuteReader();

while (myReader.Read())
{
vdep = myReader["[Depart]"].ToString();

}
myConnection.Close();
2

2 Answers

0
votes

I believe you get this error because your plugin runs in Sandbox that disallow such operations. But the main question is - why do you need this?

0
votes

Why do you forced to use this way? Especially it is not recommended to connect directly to MSCRM database.You have to use Xrm SDK