简体   繁体   中英

Run and pass some parameter to stored procedures from trigger

I'm developing a real-time project about vehicle tracking with tcpip socket and MVC. The socket inserted data from GPS to SQL Server, but when inserting a string of GPS, I have some process

For example, check over speed and out of range and ... if I want only insert string inside of the socket and write code of check, some data of GPS device string inside of SQL Server.

Can I write a trigger for that table when inserted record and pass some column of the row as a parameter to stored procedures for check data and process,...

If you have better Ideas about reducing process inside the socket, please guide me

Inside a trigger you have full access to the data inserted. So you can call a stored procedure from inside trigger and pass data to it. That's no problem. But you don't want to do this, because it slows down your socket process. Therefore you're asking for some other solution. I maybe would create an independent worker process that does the heavy calculation work.

But the most important suggestion here is - take a step back and architect your application correctly. From your question I see that you did not solve this part of your development process:

  • Using triggers for implementing business logic is a very bad idea - they should be used with care.
  • Your question, as far as I understand it, is not about MVC so why do you tag it with model-view-controller
  • The business logic (tracking vehicles) will at least partially be solved inside the data store.

A socket identifies an endpoint in a network.It is characterized by 4 "components":

-source ip
-source port
-destination ip 
-destination port

When you open a socket your os returns you a filedescriptor (handle) for the file where the incoming data arrives.

Now coming back to your scenario i understood that you are receiving data via the tcp protocol and you want to :

-insert said data into a `SQL Database`
-execute custom logic  based on some triggers.

I sketched a simple diagram for what i believe is you want:

在此处输入图片说明

So your gps data would get directly inserted in your database on one hand.
Now regarding the triggers.Yould could do them directly from SQL , or you could perform the checking in the server and then just call a stored procedure for the rest of your logic.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM