Answered by:
RelationalWebSyncService(from samples). When sql connection will be closed?

Question
-
Hello. I develop wcf sync service based on sample "WebSharingAppDemo-SqlProviderEndToEnd".
I rewrite sample and now sql connection create inside of service and read connection string from web.config.
This service create instanse for each user session and instance lifetime = usersession lifetime .
I want to create new sql connection when synchronization started and destroy them when synchrionization completed or failed, but now i have sleeping sql connection after synchronization.
I tried to close them((this.peerProvider.Connection as SQLConnection).Close()) in "EndSession" method in RelationalWebSyncService.cs. But it does not work.
Where and when i must close sql connection for release SqlServer resources immediately after the synchronization session?
What sync framework event called after end of sync session?
PS sorry for my bad english
Thursday, March 31, 2011 1:16 PM
Answers
-
You normally create the SqlSyncProvider with a sql connection object passed in in BeginSession, the provider internally clone the connection object and so that connection can be closed in BeginSession by you.
At the EndSession, you can just call YourSqlSyncProvider.Dispose(), the provider will close the connection used by it internally.
EndSession is last sync call in a sync session.
- Proposed as answer by jigu2014Microsoft employee, Editor Friday, April 1, 2011 5:58 PM
- Marked as answer by jigu2014Microsoft employee, Editor Wednesday, April 6, 2011 4:47 PM
Thursday, March 31, 2011 5:29 PMAnswerer
All replies
-
You normally create the SqlSyncProvider with a sql connection object passed in in BeginSession, the provider internally clone the connection object and so that connection can be closed in BeginSession by you.
At the EndSession, you can just call YourSqlSyncProvider.Dispose(), the provider will close the connection used by it internally.
EndSession is last sync call in a sync session.
- Proposed as answer by jigu2014Microsoft employee, Editor Friday, April 1, 2011 5:58 PM
- Marked as answer by jigu2014Microsoft employee, Editor Wednesday, April 6, 2011 4:47 PM
Thursday, March 31, 2011 5:29 PMAnswerer -
Thanks, Jin.Friday, April 1, 2011 6:57 AM
-
Hello, Jin
I can't release SqlServer resources immediately after the synchronization session. Althought i done it by your idea.
The first, i added new provider in BeginSession method
this.peerProvider.BeginSession(position, null/*SyncSessionContext*/); // Add new provider of current session this.provider = new SqlSyncProvider(); this.provider.Connection = peerProvider.Connection;
The second, i added line dispose method at EndSession()
this.peerProvider.EndSession(null); this.provider.Dispose();
Please help me!
Monday, June 6, 2011 7:47 AM