web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

sql query in crm plugin

(0) ShareShare
ReportReport
Posted on by

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

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();

i create this view (vwPayrollEmployees) in crm database 

*This post is locked for comments

I have the same question (0)
  • Daniel Wikell Profile Picture
    2,360 on at

    Is your plugin running in isolated (sandboxed) mode? If so, you are restricted in what kind of operations you are allowed. If you are running an onpremise version of CRM and want to use requests like this you need to set isolation mode to "none" for the plugin assembly.

  • Hosk Profile Picture
    on at

    can you access the SQL database from the CRM server where the plugins are deployed.  Try logging onto the server and access that SQL database with the credentials you are using in the plugin

    is the user name and password correct.

  • Community Member Profile Picture
    on at

    the user name and pass correct

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans