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