Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a custom Sharepoint WCF Service that does database calls using ADO.NET.

I have tried just about everything I can, but everytime I call the SqlConnection.Open() method, I get this exception:

Could not load file or assembly 'System.EnterpriseServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. Either a required impersonation level was not provided, or the provided impersonation level is invalid. (Exception from HRESULT: 0x80070542)

Things I've tried: New WCF Service,New database, different Connection Strings, hard code connection strings, all produce the same exception

My code sample below:

public string HelloWorld()
{
    string _connectionString = @"Data Source=localhost\SharePoint;Initial Catalog=Test;Integrated Security=SSPI;"; 

    SqlConnection dbConnection;
    SqlDataAdapter dbAdapter;
    SqlCommand dbCommand;
    DataTable dtResults;

    dbConnection = new SqlConnection(_connectionString);
    dbCommand = new SqlCommand("GetTest", dbConnection);
    dbCommand.CommandType = CommandType.StoredProcedure;

    dbAdapter = new SqlDataAdapter(dbCommand);
    dtResults = new DataTable("Results");

    try
    {
        dbConnection.Open();
        dbAdapter.Fill(dtResults);
        return dtResults.Rows[0][0].ToString();
    }
    catch (Exception ex)
    {
        throw new Exception(ex.Message);
    }            
}
share|improve this question
add comment

1 Answer

This error actually has nothing to do with your service itself. It's a permissions problem.

The issue is outlined here: Could not load file or assembly System.EnterpriseServices

Essentially, the Claims Service Account needs the "Act as part of the Operating System" policy (Act as part of the operating system), and then you need to restart the Claims to Windows Token Service and perform an IIS Reset.

Should work smooth as butter after that.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.