c# - WCF DataService throws ConnectionString exception on insert -
my wcf data service works great when fetch data it. when try insert new data, following exception:
the connectionstring property has not been initialized
the thing modified use partial class tells use connection string name:
public myextentities(string connectionstring) : base(connectionstring) { ... } : base(connectionstring) { ... }
and overrode createdatasource
, have proper context:
protected override myextentities createdatasource() { myextentities entities = null; try { entities = new myextentities ("name=myextentities"); ... return entities;
and can believe, config file contains key:
add name="myextentities " connectionstring="metadata=res://*...
the stack shows core system running, nothing methods:
system.data.entityclient.entityconnection.open()
at: system.data.objects.objectcontext.ensureconnection()
at: system.data.objects.objectcontext.savechanges(saveoptions options)
at: system.data.entity.internal.internalcontext.savechanges()
at: system.data.entity.internal.lazyinternalcontext.savechanges()
at: system.data.entity.dbcontext.savechanges()
at: lambda_method(closure , object )
at: system.data.services.providers.dbcontexthelper.<>c_displayclass4.b_0()
at: system.data.services.providers.objectcontextserviceprovider.savecontextchanges()
at: system.data.services.providers.objectcontextserviceprovider.savechanges()
at: system.data.services.providers.entityframeworkdataserviceprovider.savechanges()
at: system.data.services.dataservice1.handlenonbatchrequest(requestdescription description) <br> at: system.data.services.dataservice
1.handlerequest()
i added onstartprocessingrequest
:
protected override void onstartprocessingrequest(processrequestargs args) { if (this.currentdatasource == null) this.createdatasource(); base.onstartprocessingrequest(args); }
it's strange fetching works , uses same connection... should check?
for inserting found workaround:
public override int savechanges() { if (string.isnullorempty(this.database.connection.connectionstring)) this.database.connection.connectionstring = savedconnectionstring; return base.savechanges(); }
the connection string null on insert. thought done tried update. never hits savechanges, , exception same.
i checked uri sent service: http://*/myservice/myservice.svc/informations(guid'3091f861-0367-4a0a-9b9d-46002e5c2fc5') uses , tries record overwrite. throws same exception (connection string null).
what default context used? ef not using connection string used service operations fetch me data.
in onstartprocessingrequest method createdatasource called first, base.onstartprocessingrequest , comes exception. should set?
Comments
Post a Comment