![](/img/trans.png)
[英]WCF Data Services: SaveChanges: An error occurred while processing this request
[英]An error occurred while processing this request wcf Data service
这是我的web.config代码。
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
</system.web>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>
<connectionStrings>
<add name="SupplierProjectEntities" connectionString="metadata=res://*/SupplierDatabase.csdl|res://*/SupplierDatabase.ssdl|res://*/SupplierDatabase.msl;provider=MySql.Data.MySqlClient;provider connection string="server=127.0.0.1;User Id=root;password=sa_12345;database=supplier"" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
这是我的WCF数据服务代码。
using System;
using System.Collections.Generic;
using System.Data.Services;
using System.Data.Services.Common;
using System.Linq;
using System.ServiceModel.Web;
using System.Web;
namespace SupplierService
{
public class SupplierProjectService : DataService<SupplierProjectEntities >
{
// This method is called only once to initialize service-wide policies.
public static void InitializeService(DataServiceConfiguration config)
{
// TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
// Examples:
config.UseVerboseErrors = true;
config.SetEntitySetAccessRule("*", EntitySetRights.All);
config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
}
}
}
错误说明。 当我运行此wcf数据服务时,我得到如下错误。
<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<code/>
<message xml:lang="en-US">An error occurred while processing this request.</message>
<innererror>
<message>
Object reference not set to an instance of an object.
</message>
<type>System.NullReferenceException</type>
<stacktrace>
at MySql.Data.MySqlClient.MySqlClientFactory.get_MySqlDbProviderServicesInstance()
at MySql.Data.MySqlClient.MySqlClientFactory.System.IServiceProvider.GetService(Type serviceType)
at System.Data.Common.DbProviderServices.GetProviderServices(DbProviderFactory factory)
at System.Data.Metadata.Edm.StoreItemCollection.Loader.InitializeProviderManifest(Action`3 addError)
at System.Data.Metadata.Edm.StoreItemCollection.Loader.OnProviderManifestTokenNotification(String token, Action`3 addError)
at System.Data.EntityModel.SchemaObjectModel.Schema.HandleProviderManifestTokenAttribute(XmlReader reader)
at System.Data.EntityModel.SchemaObjectModel.Schema.HandleAttribute(XmlReader reader)
at System.Data.EntityModel.SchemaObjectModel.SchemaElement.ParseAttribute(XmlReader reader)
at System.Data.EntityModel.SchemaObjectModel.SchemaElement.Parse(XmlReader reader)
at System.Data.EntityModel.SchemaObjectModel.Schema.HandleTopLevelSchemaElement(XmlReader reader)
at System.Data.EntityModel.SchemaObjectModel.Schema.InternalParse(XmlReader sourceReader, String sourceLocation)
at System.Data.EntityModel.SchemaObjectModel.Schema.Parse(XmlReader sourceReader, String sourceLocation)
at System.Data.EntityModel.SchemaObjectModel.SchemaManager.ParseAndValidate(IEnumerable`1 xmlReaders, IEnumerable`1 sourceFilePaths, SchemaDataModelOption dataModel, AttributeValueNotification providerNotification, AttributeValueNotification providerManifestTokenNotification, ProviderManifestNeeded providerManifestNeeded, IList`1& schemaCollection)
at System.Data.Metadata.Edm.StoreItemCollection.Loader.LoadItems(IEnumerable`1 xmlReaders, IEnumerable`1 sourceFilePaths)
at System.Data.Metadata.Edm.StoreItemCollection.Init(IEnumerable`1 xmlReaders, IEnumerable`1 filePaths, Boolean throwOnError, DbProviderManifest& providerManifest, DbProviderFactory& providerFactory, String& providerManifestToken, Memoizer`2& cachedCTypeFunction)
at System.Data.Metadata.Edm.StoreItemCollection..ctor(IEnumerable`1 xmlReaders, IEnumerable`1 filePaths)
at System.Data.Metadata.Edm.MetadataCache.StoreMetadataEntry.LoadStoreCollection(EdmItemCollection edmItemCollection, MetadataArtifactLoader loader)
at System.Data.Metadata.Edm.MetadataCache.StoreItemCollectionLoader.LoadItemCollection(StoreMetadataEntry entry)
at System.Data.Metadata.Edm.MetadataCache.LoadItemCollection[T](IItemCollectionLoader`1 itemCollectionLoader, T entry)
at System.Data.Metadata.Edm.MetadataCache.GetOrCreateStoreAndMappingItemCollections(String cacheKey, MetadataArtifactLoader loader, EdmItemCollection edmItemCollection, Object& entryToken)
at System.Data.EntityClient.EntityConnection.LoadStoreItemCollections(MetadataWorkspace workspace, DbConnection storeConnection, DbProviderFactory factory, DbConnectionOptions connectionOptions, EdmItemCollection edmItemCollection, MetadataArtifactLoader artifactLoader)
at System.Data.EntityClient.EntityConnection.GetMetadataWorkspace(Boolean initializeAllCollections)
at System.Data.EntityClient.EntityConnection.InitializeMetadata(DbConnection newConnection, DbConnection originalConnection, Boolean closeOriginalConnectionOnFailure)
at System.Data.EntityClient.EntityConnection.Open()
at System.Data.Objects.ObjectContext.EnsureConnection()
at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
at System.Data.Objects.ObjectQuery`1.GetEnumeratorInternal()
at System.Data.Objects.ObjectQuery.System.Collections.IEnumerable.GetEnumerator()
at System.Data.Services.WebUtil.GetRequestEnumerator(IEnumerable enumerable)
at System.Data.Services.DataService`1.SerializeResponseBody(RequestDescription description, IDataService dataService)
at System.Data.Services.DataService`1.HandleNonBatchRequest(RequestDescription description)
at System.Data.Services.DataService`1.HandleRequest()
</stacktrace>
</innererror>
</error>
错误说明。 我首先在sql server中创建了这个数据库。当我为sql server提供了wcf数据服务时,它就可以正常工作了。该数据库与mysql数据库相同。 但是现在已经为MySQL数据库提供了WCF数据服务,然后出现了这个错误。 如上所示。因此请为我解决此错误,请务必解决此错误。
我问这个问题从mysql数据库中检索数据的版本是6.7.4.0
我可以得到我问题的答案。
答案是我刚忘记在参考文件夹中添加Mysql.data.dll和mysql.data.entity.dll 。 因此,在参考文件夹中添加此dll之后,我可以解决上述错误,因此您也可以尝试。 我希望这会有所帮助。
这将以等宽字体显示。 前四个空格将被删除,但所有其他空格将保留。
Markdown and HTML are turned off in code blocks:
<i>This is not italic</i>, and [this is not a link](http://example.com)
要创建块而不是内联代码范围,请使用反引号:
$
字符只是window.jQuery
的快捷方式。 如果要在列表中包含预格式化的块,请缩进八个空格:
也是如此,但是现在遵循一个代码块:
Skip a line and indent eight spaces. That's four spaces for the list and four to trigger the code block.`enter code here`123"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.