Failing to access external SQL database from CRM Plugin while debugging - debugging

I'm having trouble accessing an external database from a CRM plugin.
The error I receive is:
"Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=xxx' failed."
The code runs great locally within a "unit test". I made sure to set the plugin isolation mode to "none".
I tried looking to this article for help, and tried everything it suggested with no luck.
Here is the current code I'm using:
var conn = new SqlConnection(#"Server=MyServer\Instance;DataBase=MyDB;User Id=MyUser;Password=MyPassword;Integrated Security=false;");
conn.Open();
I also tried this connection string and giving the NT AUTHORITY\NETWORK SERVICE user access to the database.
var conn = new SqlConnection(#"Data Source=MyDS\Instance;Initial Catalog=MyDB;Integrated Security=SSPI;");
conn.Open();
I'm on Dynamics CRM 2015 On-Premise.
Update: I found out it was working when I didn't debug, but I got the error when I try to debug it through the plugin registration tool. Any idea on why that would happen?

A SQL connection will require "full trust" to establish which the CRM plugin sandbox does not run within.
We run CRM 2013 On-Premise and I frequently make calls to external databases within custom plugins and workflows, but to overcome the security issues - I created a web service which handles these requests.
For example, a call to update a record in DB2 when an account is updated would work like this:
Account record updated in CRM
Account plugin fired
Establish connection to MyCompanyWebService
Call UpdateDB2 (method within MyCompanyWebService)
Of course you have the overhead of having to develop a separate web service, but (on the bright side) it allows you to separate the logic and you can fully control the trust level within your web service.

The plugin registration tool has only limited debugging capabilities. It was designed for CRM Online, where you cannot use the debugging options of Visual Studio. In OnPremise deployments use either remote debugging or install Visual Studio on the CRM Server. The last one is the recommended approach.

That issue looks like your code is running in partial trust (Sandbox), it's failing even before trying to connect to the SQL Server instance as it doesn't have permissions to instantiate a SqlClient.
In Dynamics CRM 2015 On Premise you don't have to run plugins in Sandbox if you don't want to. Sandbox is a requirement for Dynamics CRM online only.
Did you try running outside the Sandbox? Did you do an iisreset after changing the plugin isolation maybe?
Here is an article with more details.

Related

Exception while using Windows Azure Caching : No such host is known

I am trying to get started with Azure and am trying to use the Caching feature. I created a cloud service project and added a Cache worker role and a web role. I installed "Windows Azure Caching" nuget into projects for both the roles and added the name of cache worker role as identifier in DataCacheClients element in web.config of the web role.
I added the following code into the web role:
DataCacheFactory cf = new DataCacheFactory();
DataCache c = cf.GetDefaultCache();
When I try to run this locally on the emulator, I get the following exception:
ErrorCode<ERRCA0017>:SubStatus<ES0006>:There is a temporary failure.
Please retry later. (One or more specified cache servers are unavailable,
which could be caused by busy network or servers. For on-premises cache clusters,
also verify the following conditions. Ensure that security permission has been granted
for this client account, and check that the AppFabric Caching Service is allowed through
the firewall on all cache hosts. Also the MaxBufferSize on the server must be greater
than or equal to the serialized object size sent from the client.).
Additional Information : The client was trying to communicate with the server: net.tcp://MvcWebRole1:24233.
Inner Exception : No such host is known
Can you please tell me what I am missing here?
Azure SDK used : v2.0
Timing of your question couldn't be better. We also faced exactly the same issue and were scrathing our head as to what the problem could be. We had one project where everything worked perfectly fine and in one we were getting the same error. Based on our research, we have identified the problem with the Nuget package for caching. It seems a new version (2.1.0.0) was released yesterday and we found that if we install that package, we get this error. Can you check the package version in your case? The documentation states that this new version can only be used with the latest SDK (2.1) released today.
One solution would be to uninstall version 2.1.0.0 and install version 2.0.0.0. To install version 2.0.0.0, open Package Manager Console (View --> Other Windows --> Package Manager Console) and type following command there:
Install-Package Microsoft.WindowsAzure.Caching -Version 2.0.0.0
This fixed our problem. Hopefully it should fix yours too.
Here is a link to the Windows Azure Cloud Integration Engineering blog on how to deal with this same issue. They recommend upgrading to Azure SDK v 2.1 or rolling back as the accepted answer states.
http://blogs.msdn.com/b/cie/archive/2013/08/08/windows-azure-caching-2-1-0-0-no-such-host-is-known.aspx
This exception could also occur under compute emulator if for the role in the client library configuration there is no cache configured. In my case this happened on purpose, since the cache emulator has some problems that can slow down the test and debugging on the service.
In previous version of Windows Azure Caching, in this scenario the construction of DataCacheFactory would fail with an exception (handled by my code); with Windows Azure Caching 2.1 (and Azure SDK 2.1) in this same scenario the code would consider the role name as a server address and thus on DataCache construction would try to communicate with the non existing cache -- this leads to a 3 minute wait and the exception reported in the question.
I have changed my code to detect the new situation for this scenario -- you can find more detail in this SO question.

No entering Credentials for an SQL Azure report

Situation:
I have set up an Windows Azure webrole in visual studio 2010 to get a SQL report from the reportserver and everything works.
Problem:
Everytime I want to check the report and run the program I have to enter the credentials for the report, I don't know how to turn this off. Even on the server I have to enter them but I can't seem to find a way to make the report public..
I find the management quite confusing..
Does anybody know how to do this?
This is what it looks like when running the program
Based on what you provided:
You have an ASP.NET Web Role which connects to SQL Azure Report Server
Whenever you launch your ASP.NET Web Role you need to enter credentials to access the report as shown in the image
You are looking for a way to add username/password within the WebRole so reports can be viewed by anyone accessing the webpage.
Here is the answer:
In your SQL Azure Reporting via Report Viewer control based Web Role, you can add Username and Password into Global.config along with RSServer (Report Server) Name
This way when your ASP.NET based Report Viewer application will run, it will have required credentials already available to connect to report server.
The following link shows exact details about how you can achieve your objective:
http://oakleafblog.blogspot.com/2011/10/pass-summit-sql-azure-reporting_8267.html
You can get SQL Azure specific report viewer samples from the link below:
http://social.technet.microsoft.com/wiki/contents/articles/sql-azure-reporting-samples.aspx

C# MVC3 - New Membership Providers (System.Web.Providers) and old Membership classes (System.Web.Security)

I got my app running very well when I was testing locally, with Membership providers and Database. My nightmare began when I tried to run it in Windows Azure plataform.
Since then, I read a lot of articles about running aspnet_regsql in Sql Azure, and the new universal Membership providers. But I can't realize how to use the new Providers, and I'm getting really confused about System.Web.Providers and System.Web.Security classes and methods. When I tried to create a new user with the new Providers, the creation failed with a Null Exception, even if I had all the parameters placed and the build was ok.
My project is totally ready, I just need to upload it to the host.
How could I make it run in Windows Azure easily? Or should I learn how to use the new universal Providers and adjust all my project to that?
It appears that System.Web.Providers is required to run your application on Azure, at least without any heavy code lifting. Scott Hanselman outlines the basics of installing and using System.Web.Providers in his recent blog post: Introducing System.Web.Providers - ASP.NET Universal Providers for Session, Membership, Roles and User Profile on SQL Compact and SQL Azure.
Another resource that may be helpful is Wade Wegner's post Deploying the Windows Azure ASP.NET MVC 3 Web Role.
In short, after installing System.Web.Providers in your project using NuGet, it will reconfigure your web.config to include two connections strings, one for ApplicationServices, and another for the DefaultConnection. You will need to updated these with your Azure connection string, but make sure you append "MultipleActiveResultSets=True;" to both connection strings.

Simultaneous db4o file access

How can I simultaneously access my .db4o database from the Visual Studio's Object Manager Enterprise (OME) db4o plugin and from my application?
I'm starting out with db4o, integrating it with an ASP.NET MVC application. I have a two-layer repository access pattern set up using StructureMap for IoC and I keep getting DatabaseFileLockedException erros in VS when debugging while using OME.
When you want to access a db4o database file from multiple applications at the same time, you need the client-server-mode. So, either your application or a special "db-server only" application has to open the file as server, then both your application and the OME should be able to connect to this server.
The documentation has an example for this.
I never used OME, so I have no idea how to configure it there.

MS CRM Custom Workflow to access Project Server web service

I am trying to create a custom workflow in ms crm 4 so that when a task is completed it will take some of the attributes of the task and add an entry in project server on a timesheet. I am able to access the project server web services (PSI) and create a time sheet entry from a c# console app and I can do other custom workflows in crm not related to project server. When using the Project Server web services (PSI) I have to reference and include 3 office project dll's but I am unsure how to get those registered in CRM when i do the custom workflow plugin registration. Any thoughts would be helpful.
Thanks
In my experience, you're either going to have to deploy those DLL's to the Server\bin directory or merge them with your DLL using something like ILMerge and register it all as one big chunk.

Resources