not able to perform multitasking in linq to sql data context - c#

I have Windows Service which will handle JOBs posted via web sites, user can request long running job to WS. WS will pick that job and do necessary calculation with data and update the data into database. The number of record update more than 15 lacks.
So the issue is if the JOB is running via WS and same time if you try to access the website or if you try to perform any operation on the page it will show lodging page till the WS will finish the task.
The Web Application & WS is using common database via LINQ to SQL DBML. The Data Access layer is separate class library and referred by WS and Web Application. The database is in SQL Server 2008 R2
I am not able to find the root cause of the above.
Please help on this

By mistake I have made DataContext object as static.
DataContext object never be static.

Related

Running single window service on multiple server in active active mode

In my application I am running a windows service on a Web server. This service calls a single table and selects and update the table as well as insert some record in another table. When this service is deployed on multiple web servers running in an active/active configuration, then it will process records, multiple times and also create duplicate records in a table.
How can I prevent this problem so that my service running on multiple server will process unique records as well as I want that if my one of my server goes down then second server will process all the requests.
I am thinking of some custom queue kind of concept but did not figure out how to implement this.
You need to implements a sql semaphore, here is some example:
http://www.sqlservercentral.com/articles/Miscellaneous/2649/
http://blog.udby.com/archives/14

Simultaneous data access from different threads

Hi I am developing a WinForms app which is using LocalDb with EF for data access.
So far the db access in my WinForms app was performed only once at a time, just by calling:
using (var context = new EfDbContext())
{
// do something on context entities
}
when needed.
Now I am facing a new requirement - I need to create an extra background service which will be used to periodically get the data from files located on some FTP servers, and then - update / insert the new data within this SQL LocalDb.
What I would like to achieve is to grant simultaneous access to the SQL LocalDb data for both WinForms app and this new background app (service), so that it would be possible for the user to view data from Db (in WinForm app), while an update of the data is performed in the background (by the service).
I would like to ommit the resources blocking for each other.
Can that be done (and how to do that)?
Thanks!
UPDATE: I forgot to mention that the data sets which will be read from ftp files and then inserted into database may be quite large ~20-50k of records, each record consist of decimal field, DateTimeOffset field, and few Int32 fields.
Just use it and don't worry for now about concurrency. SQL Server widely used in highly concurrent applications like ASP.NET Web Apps and your example isn't so special. Blocking can be a problem when using transactions with write operations. But there are many Transaction isolation levels to solve this problem and it's irrelevant for now for your task I think

Only update data in local database from web service if the data is new

I have coded a C# Web API 2 web service, and am wanting to retrieve this data in an android application that I have coded.
I wish to have a local SQL database on my android device that stores the data from the web service.
Whenever data is to be used in my android application, I wish to check to see if the local database data is the most up to date, and if it isn't, then I wish to retrieve the latest data from the web service.
I am thinking of the following:
Each time data is saved into the local database, save an integer value as an update number.
Whenever data is required, retrieve the latest update number from the local database, send a request to the web service with this update number, and only return data if the web service data has a newer update number.
Would this work well? Is there a better approach to this problem than my above idea? Are there any disadvantages or errors that could occur?
Thanks in advance.
I did exactly same thing with my synchronization algorithm. It's like this.
My web service methods gets datetime parameters, web service sends objects only created or modified after that time.
On the mobile side, I keep synchronization start time, and for the each synchronization, i send previous sync start time. (By the way, I ask date to server just before sync starts)
I dont keep sync end time, because some of the data may be modified after sync started.
I have done similar thing in my sync adapter where user click on sync and it get data from web feeds and store only updated data into sqlite.
refer to SyncAdapter.java file of sync adapter sample provided on http://developer.android.com/training/sync-adapters/creating-sync-adapter.html

Alternative solution for executing a long running SP via a web service

I need to tell the Database Handler that it should run a script which generates 300-500MB of data, then notify my C# application that the script has completed.
After that I need to get the newly created data to my C# application, manipulate it then send it to an FTP-server.
One way to do this would be to call the SQL-server via a web service, let the Database Handler run the script, then return the data. The C# application would then manipulate the data and finally send it by FTP. However because of the size of the data and the run-time of the script being around 1 hour this method is far from optimal.
Any suggestions on a better solution?
EDIT: I forgot to mention some important parts. SSIS was something I thought of as well. The problem is that the database is on a different server which doesn't have ports open for sending via FTP.
I would implement this as a service. Use the web service to allow users to request execution of the script (queue a request), but actually execute the script from the service (read the queue and perform the action). You have far greater control of the entire data gathering and delivery process from within the service.
My own strategy would be to develop a standalone application (installed on the server) to perform the data retrieval, manipulation and FTP transfer. This application could be executed by code in your ASP.NET application as a result of some user interaction perhaps, and could update the database as to its progress so that your user could have some feedback via the ASP.NET web interface (ajax polling or loading a status page).
Have you considered using SSIS? One of the things it is really useful for is controlling data-centric multi-step workflows.

Consume a WCF service from a console app as part of a SQL job?

I'm working with one WCF service which will be consuming records I queue up for it with another. Service A will package up an object containing a series of records (I guess an XML document, haven't nailed down the format yet) queried from a database, and submit it to Service B for processing.
Service B is on a separate department's system and is out of my control, so I'm using my service to package the data to conform to B's inputs.
I'm thinking of instantiating my service via a client in a console app, which would be called as part of a SQL job on MS SQL 2005.
Could someone please suggest alternatives and any better ideas?
You might want to consider packaging your service A code into SQLCLR and call it like another stored proc.

Categories

Resources