Recently i created an application which could get the password of the user, whose username is provided as the parameter, i checked the code, its working fine, now i created a class library so that i can add this assemnbly in sql server 2008, below is the code of my class library.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Security;
public class DnnUserCredentials
{
public static string GetUserPassword(string username)
{
MembershipUser objUser = Membership.GetUser(username);
return objUser.GetPassword();
}
}
i created the assembly in sql server 2008 like below
CREATE ASSEMBLY DNN_USER_CREDENTIALS FROM 'E:\NBM SITES\SqlProjectDll (DO NOT DELETE)\UserCredentials.dll' WITH PERMISSION_SET = SAFE
i got the command completed successfully message, then i created a function like below:
ALTER FUNCTION [dbo].[fn_UserCredentials](#UserName [nvarchar](max))
RETURNS [nvarchar](max) WITH EXECUTE AS CALLER
AS
EXTERNAL NAME [DNN_USER_CREDENTIALS].[DnnUserCredentials].[GetUserPassword]
here too i got the command completed successfully message, now when i tried to call the function using
SELECT [dbo].[fn_UserCredentials]('host')
it throws me below error:
A .NET Framework error occurred during execution of user-defined routine or aggregate "fn_UserCredentials":
System.Security.SecurityException: Request for the permission of type 'System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
System.Security.SecurityException:
at DnnUserCredentials.GetUserPassword(String username)
any solutions.
Not sure what can be the problem. First try to change the PERMISSION_SET to Unrestricted.
When this does not help try to debug the DLL from visual studio.
You need to set PERMISSION_SET = UNSAFE to get access to remote resources.
Also you might want to set TRUSTWORTHY flag to ON.
ALTER [<DBName>] SET TRUSTWORTHY ON
GO
CREATE ASSEMBLY [<assemblyName>]
--user with sysadmin rights for this DB may be required for deploing
AUTHORIZATION [<someSysadmin>]
FROM '[<pathToDll>]'
--compiled with unsafe to access EventLog for example
WITH PERMISSION_SET = UNSAFE
GO
Related
I'm using Azure Functions and want to write code that reads/writes to Dynamics CRM Online. I added the CRM 2015 SDK DLLs (all of them) to a bin folder under where the function.json file resides per Microsoft's documentation.
The function compiles fine.
When running the function I get this error:
Exception while executing function: Functions.CrmTest1. mscorlib: Exception has been thrown by the target of an invocation. Could not load file or assembly 'Microsoft.Xrm.Sdk, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
Here's the function body (just a small test sample):
#r "Microsoft.Xrm.Sdk.dll"
#r "Microsoft.Xrm.Client.dll"
using System;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Client;
using Microsoft.Xrm.Client.Services;
public static void Run(string input, TraceWriter log)
{
var connectionString = "AuthType=Office365;Username=me#contoso.com; Password=MyPassword;Url=https://contoso.crm.dynamics.com";
CrmConnection connection = CrmConnection.Parse (connectionString);
using ( OrganizationService orgService = new OrganizationService(connection))
{
var query = new QueryExpression("account");
query.ColumnSet.AddColumns("name");
var ec = orgService.RetrieveMultiple(query);
log.Verbose(ec[0].GetAttributeValue<string>("name"));
}
}
There's no indication in the log files what needed assembly can't be found.
What am I missing with getting this to work? How can I find out what DLL is needed but is not found?
Tim,
The latest deployment that went live today contains the fix to address the issue you ran into. Please try again (you may need to restart your site to pick up the latest version if you had functions running) and let me know if you have any problems.
Thanks again for reporting this! I'm looking forward to seeing what you'll put together with Functions and Dynamics CRM.
I have a WebApp on Azure that uses a dll. This library needs Interop libraries x86 and x64.
Sometimes, at the restart of the App (I suppose), the App fails due to an exception:
System.EntryPointNotFoundException: Unable to find an entry point named 'sqlite3_config' in DLL 'SQLite.Interop.dll'. at System.Data.SQLite.UnsafeNativeMethods.sqlite3_config_none(SQLiteConfigOpsEnum op) at System.Data.SQLite.SQLite3.StaticIsInitialized() at System.Data.SQLite.SQLiteLog.Initialize() at System.Data.SQLite.SQLiteConnection..ctor(String connectionString, Boolean parseViaFramework) at T_Dox.WebService.SQLiteDb.CreateConnection() at WebService.CeDb.Connect()
The SQLite used is the SQLCipher's one.
What am I missing here? I don't understand why the app stops working suddenly even if I don't make any changes.
The App is a Web Service (.asmx file) that uses a data access layer to perform some business logic.
It was under a web site project, then we moved it into another project, a webapi\mvc project.
The routing bypasses this extension, so it works as before, a simple web service call.
The called web method initializes a business class loaded from another .net library (a VB.Net library).
Inside, this class uses a wrapper to a sqlConnection, in this case the SQLiteConnection.
In its constructor it starts an SQLiteConnection, and normally it works.
Then it performs some CRUD operations ...
So I can represent the operation this way:
[WebService(Namespace = "...")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class SampleService : System.Web.Services.WebService
{
[WebMethod]
public ServerInfo Test()
{
var sampleBusinessClass = new SampleBusinessCLass();
sampleBusinessClass.DoSomething();
using(var connection = new SQLiteConnection()) //the constructor is the parameterless one
{
//...
}
}
}
And the stack will be this (this is not the real one):
System.EntryPointNotFoundException: Unable to find an entry point named 'sqlite3_config' in DLL 'SQLite.Interop.dll'.
at System.Data.SQLite.UnsafeNativeMethods.sqlite3_config_none(SQLiteConfigOpsEnum op)
at System.Data.SQLite.SQLite3.StaticIsInitialized()
at System.Data.SQLite.SQLiteLog.Initialize()
at System.Data.SQLite.SQLiteConnection..ctor(String connectionString, Boolean parseViaFramework)
at xxx.WebService.SampleService.Test()
It always works, but sometimes it starts to launch this error until the stop and start of the web application on iss (in our case: Azure).
Inspecting the System.Data.SQlite.dll I can clearly see the entry point and actually it always passes this internal code (no conditions that can bypass this part) and it generally works.
The System.Data.SQlite.dll (1.0.96.0 version) is provided by SqlCypher product. I think it is the original System.Data.SQLite one because at first sight I can see the same assembly manifest and content.
The interop System.Data.SQLite uses is probably modified by SqlCypher team to give their features.
To avoid possible issues we put the interop in the path /bin/x64, then we compile our web app ONLY in x64 and it runs on a x64 environment.
i am working on network application, and im sending this object from client to server..
at rcving i get an error.. this is my class of which object im sending
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
namespace DrawingClient
{
[Serializable]
class myClass
{
public List<Point> points = new List<Point>();
}
}
and at rcving exactly where im de serializing the object.. im getting this exception..
Unable To Find Assembly drawing client, version=1.0.0.0, Culture=neutral PublicKeyToken=nulland i have all the assemblies at both server and at client end.. im testing it on my localhost.. mean both client and server are at localhost.. and same namespaces reffered in both applications.. im using tcpclient and tcplistener..
i made a dll in which i placed this class, and than referenced that dll in my Project at both ends and problem is solved..
actually when working with binary serialization assembly information also travels like my project name was rummykhan and my class name of which object i was serializing was book so the assembly information now include rummykhan.book and at client side assembly information is rummykhanclient.book so it was not deserializing.. when i made a dll and referenced it to both ends now assembly information is same and now its working.
PS
another part of information was also traveling along that was version information.. which we can control from the properties of the project.. and it must be same also..
I have created a plugin and it was registered successfully (Sandbox Isolation Mode).
Inside Plugin execution, I want to create an object of OrganizationServiceProxy, which is using another CRM details. Using the code below:
Uri oUri = new Uri("https://yourorg.api.crm5.dynamics.com/XRMServices/2011/Organization.svc");
//** Your client credentials
ClientCredentials clientCredentials = new ClientCredentials();
clientCredentials.UserName.UserName = "YourAccount.onmicrosoft.com";
clientCredentials.UserName.Password = "YourAdminPassword";
//Create your Organization Service Proxy
OrganizationServiceProxy _serviceProxy = new OrganizationServiceProxy(
oUri,
null,
clientCredentials,
null);
I am getting Security Exception:
System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
Searched for the same issue but not working, Please suggest.
What version of .NET are you building this in ?
check out these links:
link 1
link 2
This error is usually caused by some process that doesn't have enough permissions to run. I had this issue before and it solved my problem.
I basically used the new AddFullTrustModuleInSandboxAppDomain method. (check links for more info)
Where exactly do you get this error? When trying to create the proxy ? Or when the plugin is trying to do something (create a report, .. ) ?
I have searched a lot but the plugin is registered in sandbox mode so it, doesn't allow to access external services.
Found the best way to use it.
Created Azure web service and use the service in Plugin, it works.
I have created a simple console project with the following code:
using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var farm = SPFarm.Local;
Console.WriteLine(SPFarm.Local);
Console.ReadLine();
}
}
}
The SP2013 Server is installed in a virtual server from Cloudshare. There is another vm for the SQL Server 2012 and another one for the Active Directory 2012 (domain is AD2012.loc).
When I open the project using the AD2012.loc/Administrator account, it works perfect. But when I open it using my account (which is in AD2012.loc and in the Administrators group) SPFarm.local is null.
I know is a permission thing but since I have to rely on this SPFarm.Local object to use in another project, that will be executed in several servers where I don't have access to and I can't be sure they will executed as the Administrator, is there anything I can do to maybe impersonate the code to run as the SPFarm admin or something?. I have tried runned with the SPSecurity.RunWithElevatedPrivileges with no luck.
UPDATE
I've tried running the above code impersonating the SPAdmin user but still getting null.
I can't just give access to the user because this will run in client machines, and I can't tell them to give access to the SPConfig db. So I need a way to do it in the code, impersonating or something.
I am not sure about this will work or not
i will give you two links hopw any one will work for you.
SPFarm.Local is return null
OR
http://blogs.msdn.com/b/ekraus/archive/2009/11/13/sp2010-spfarm-local-is-null-or-web-application-could-not-be-found.aspx