I have a web service that inserts a row into a Database Table.
After this a windows service will read this table and updates this table.
Inserts a Blob into FILE_IMAGE column
STATUS to COMPLETE
My Web Service has to wait till this table STATUS and FILE_IMAGE column gets updated and then read the FILE_IMAGE.
My doubt is : What logic is ideal for my web service to wait for the table to get updated.
I dont want to use Thread.Sleep or something similar to that. My database is Oracle and code behind is C#.
You could write an AFTER UPDATE trigger on the oracle table which sends the ROWID to another web service which performs the necessary steps. Thread.Sleep will always have the potential of not waiting long enough.
Related
I need to know the best way to monitor a SQL server DB table if it is updated everyday or not. If it is not updated on a particular day, then send an alert message to a particular mail.
Create a job on SQL Server Agent that runs every day. On that job, design a script that checks if the table is updated.
To check if the table is updated, you should do something like save the value of a particular column from the previous day and compare it to the value of n from the current day.
Or you can design a trigger on that table. If the table is updated, the trigger will fire and save somewhere the fact that the table was updated.
If the table is not updated send an email.
If you don't know how to sent an email from SQL server here are the steps you should follow:some steps
.I am using azure sql database with my app hosted in azure
I tried using a Automation account, created a runbook but doesnt fetch any results
FullyQualifiedErrorId : CommandNotFound Exception.
CategoryInfo :Object Not Found: (SqlAutomation/RB_Record_AzureScheduler) Command Not Found exception
You can use the "when an item is created" and the "when an item is modified" triggers for SQL in Azure Logic App to react to data changes.
You can add condition and choose an action like sending an email.
The SQL connector in Azure Logic Apps uses a polling mechanism to query a table for changes using a TIMESTAMP / ROWVERSION column. This data type is specifically designed for this kind of processing in SQL. The polling query essentially selects all rows where the rowversion is greater than the last polled value. The behavior is reliable since the column is controlled by SQL Server and the performance is extremely fast in the case where there is no new data. When there is new data, the performance is comparable to a simple row query.
For more information, please read this article and this one too.
IDE: Visual Studio, C# .net 4.0, Winforms application
Is there any way in SQL Server to implement a column in a table which can set itself automatically to 0 when it has not received any ACK (acknowledgement) signal from the application side?
The requirement is I want to keep a column which can keep track that Is application is open or it has been closed?
One way to implement is using the OnClose() event, i.e. on Close() I can change it's value to 0. but the problem is suppose application got hanged for some reason or Power is gone than the value in database will not be updated to zero.
So I want to create an automated column which can track this situation and make itself zero when the application is not sending any request or idle means closed.
please suggest how to handle this.
You can't do that. The only thing you can do is to save GETDATE() in a column in a table as the last activity time of the application and invoke the stored procedure from a high-priority thread every 10 seconds for example.
When you want to know if the application is alive or not, just check this value, if more than 10 seconds is passed since then, you app is gone.
UPDATE:
A more precise but complex approach would be to listen on a socket inside your application and then whenever you want to know if the application is alive, send a request from your sql script to PING the application. You should use CLR programming for this approach, but I think the first one will be practically enough.
Considering it will be a multiple instance scenario where multiple instances of the application can point to same database. You can try the following:
Create a separate table to maintain sessions. This table would contain three columns 1)Machine name or IP 2) Session Id (GUID) and 3) TimeStamp.
Whenever application starts create a new session id and make an entry into this table it means new session is started.
Keep on updating timestamp on every request based on session id.
Have a timeout configured somewhere in web.config or database which will come in handy later.
Now when application is exiting gracefully then delete the row from the table.
Now if application crashes the row won't be delete so next time when application starts you can check if the row already exists. Use machine name or IP to query to the table.
Use the timeout setting configured in (3) above to determine since how long the application is idle.
I'm coding a M2M data capture system using SQL Server 2012 and .net 4.5, the scenario is:
I have a remote data capture app, a web service, a DB.
The app captures data and invoke the web service to upload the data to the DB.
The web service call a "insert" storedproc to write raw data directly in Table A; and then, the web service returns a value telling that the insert was successful or not.
Now, a post-process storedproc needs to be run after the insert process to update another table (Table B).
Previously I used 'job agent' but since the required polling interval changed to 'less than 5 minutes', for the efficiency and real-time reason, I want to avoid to use the 'polling'.
Ideally, I want the app to be able to call the web service and get the return message/value, after that, the DB fires a stored proc to do the post-process work; the work may take longer so the app doesn't need to wait all the processes are done.
Can I fire the post-process sp from DB side? since the DB knows when the insert is done, and it saves communications from outside the DB.
Any suggestions?
You might think of using trigger plus Service Broker. In this way, the trigger will send a message to a queue. service broker will be fired to process the message. It decouples your table A update and table B update. If only use trigger to call table B, it will hold your table A update until the table B update finished.
i was trying to connect a local machine with my web application.i need to get some data from local machine and insert it into my online table.User clicks a button and a new column is added to a online table named request which has status "new" in the beginning.i went for sql dependency which i installed as a windows service in local machine and it check the request table for any new insert.the service fetches some data from the local machine and posts it to the online database and change the status field in request table to "updated".
Now my problem is how can i notify my website that required data has been inserted in the table?? i need to watch the request table continuously until the value in the status column changes to updated.can i go for thread or timer ??
You can write an INSERT trigger in the live database which your website is using.
Use another Table RequestUpdates and write an INSERT trigger that adds a value to the table RequestUpdates in the live database.
Design your website to load the RequestUpdates table.
And when the user loggs in and Requests have been viewed, change the status in the live table to viewed.
In this way new requests will be shown that are not viewed the next time.