473,851 Members | 2,236 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Synchronizing stored procedures

I'm writing a VB6 app which calls several stored procedures on my SQL
Server DB.

The first stored procedure must complete its inserts before the second
stored procedure can query the modified table for its results. My
problem is that
the second stored procedure occasionally returns a different result
set, acting as if the first stored procedure didn't complete (or
didn't run).

So how do I ensure (or test/poll?) that the first stored procedure
runs to completion before returning control back to my VB app?

Thanks in advance,

Ralph
Jul 20 '05 #1
9 5490
cr*******@hotma il.com (Ralph Cramden) wrote in
news:e2******** *************** ***@posting.goo gle.com:
I'm writing a VB6 app which calls several stored procedures on my SQL
Server DB.

The first stored procedure must complete its inserts before the second
stored procedure can query the modified table for its results. My
problem is that
the second stored procedure occasionally returns a different result
set, acting as if the first stored procedure didn't complete (or
didn't run).

So how do I ensure (or test/poll?) that the first stored procedure
runs to completion before returning control back to my VB app?

Thanks in advance,

Ralph


Might it make sense to combine your procedures? Or perhaps create a third
stored procedure that calls the first then the second in sequence?
Jul 20 '05 #2
[posted and mailed, please reply in news]

Ralph Cramden (cr*******@hotm ail.com) writes:
I'm writing a VB6 app which calls several stored procedures on my SQL
Server DB.

The first stored procedure must complete its inserts before the second
stored procedure can query the modified table for its results. My
problem is that
the second stored procedure occasionally returns a different result
set, acting as if the first stored procedure didn't complete (or
didn't run).

So how do I ensure (or test/poll?) that the first stored procedure
runs to completion before returning control back to my VB app?


Do you call the procedures from different threads or asynchronously? That
would be the only way for the second procedure before the first have
completed. In both cases, you would need synchronization in the client
code.

I suspect that your real problem is something else. That is, you are calling
the two procedures sequentially from the same thread, but there is some
flaw of logic, causing the incorrect result. It could also be that the
first procedure runs into an error condition, which you fail to handle
properly in the application code.

That is, if you are calling stored procedures in the plain vanilla way,
you don't have to worry about synchronization , since all calls to SQL
Server are synchronous.

--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #3
My fear is that I'm calling the stored procedures asynchronously
and I don't want to.

The Project properties dialog box shows that the app is a standard
EXE project type (threading model is grayed out (so I'm assuming
a single thread)).

The SQL server though is a multiple CPU(4) platform would that
make a difference?

How would I synchronize the client code?

Erland Sommarskog <es****@sommars kog.se> wrote in message news:<Xn******* *************** @127.0.0.1>...
[posted and mailed, please reply in news] Do you call the procedures from different threads or asynchronously? That
would be the only way for the second procedure before the first have
completed. In both cases, you would need synchronization in the client
code.

I suspect that your real problem is something else. That is, you are calling
the two procedures sequentially from the same thread, but there is some
flaw of logic, causing the incorrect result. It could also be that the
first procedure runs into an error condition, which you fail to handle
properly in the application code.

That is, if you are calling stored procedures in the plain vanilla way,
you don't have to worry about synchronization , since all calls to SQL
Server are synchronous.

Jul 20 '05 #4
Ralph Cramden (cr*******@hotm ail.com) writes:
My fear is that I'm calling the stored procedures asynchronously
and I don't want to.
I don't want to scorn you, but if you don't know if you are writing
a synchronous application or not, you are a very confused VB programmer.
(And if you really want certainty, you would have to ask in a Visual
Basic newsgroup; that's not really an SQL Server question.)
The SQL server though is a multiple CPU(4) platform would that
make a difference?
That has nothing to do with it.
How would I synchronize the client code?


It does not sound like you would need to. If your code looks like this:

Set cmd = new ADODB.Command
cmd.ActiveConne ction = cnn
cmd.CommandType = adCmdStoredProc
cmd.CommandText = my_first_proc
cmd.Execute
Set cmd = Nothing
Set cmd = new ADODB.Command
cmd.ActiveConne ction = cnn
cmd.CommandType = adCmdStoredProc
cmd.CommandText = my_second_proc
cmd.Execute
Set cmd = Nothing

There is nothing to synchronize. cmd.Execute blocks until SQL Server
has completed execution.

If you are using separate threads, or the synchronous capabilities of
ADO and issue the commands on two separate connection, you have indeed
quite a few interesting problems. Then again, that's not a path you
should not take if you don't know what you are doing.

--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #5
A DTS package would do this for you really easily.
Jul 20 '05 #6
Ryan (ry********@hot mail.com) writes:
A DTS package would do this for you really easily.


Eh? I don't know much about DTS, but there is actually one thing I've
used DTS for, and that is to test the multi-threading capabilities of a
Perl module for SQL Server access. Because in DTS, things really happens
in parallel. What implications that has for what DTS is used for, I don't
really know, but I have noticed that you can arrange tasks, so that task B
does not start before task A has completed, but you can also arrange for
A and B to be in parallel if you like.

Now, whether this has any relevance for Ralph's question, I don't know,
but my guess it has not.
--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #7
Erland,

My understanding of the problem was that there was a need to run two
SP's. The second SP needs to run after the first has completed. Doing
this in a series of stored procedures or an SP that runs both could
force the execution plan to determine that it's better to run the second
SP before the first (hence the problem).

I was suggesting the DTS as an option as you can make a stored procedure
'wait' until the sucess of a prior SP. In it's most simplistic terms,
this should solve the problem. It is really good at running things in
parallel as well, but this may work in this case.

I would have tried creating a small DTS package that runs the second SP
on success of the first task. This would take a matter of minutes to do
and would not require changing the SP's.

I may well be wrong, but given that it would take a short time to set up
and test, I felt it might be worth a look. Hopefully I have not missed
the point.

Ryan

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #8
Ryan (an*******@devd ex.com) writes:
My understanding of the problem was that there was a need to run two
SP's. The second SP needs to run after the first has completed. Doing
this in a series of stored procedures or an SP that runs both could
force the execution plan to determine that it's better to run the second
SP before the first (hence the problem).

I was suggesting the DTS as an option as you can make a stored procedure
'wait' until the sucess of a prior SP. In it's most simplistic terms,
this should solve the problem. It is really good at running things in
parallel as well, but this may work in this case.


That's correct, that DTS gives you a synchronization mechanism. (Hey,
that is as much I know about DTS.)

However, you can achieve the same with:

Set cmd = new ADODB.Command
cmd.ActiveConne ction = cnn
cmd.CommandType = adCmdStoredProc
cmd.CommandText = my_first_proc
cmd.Execute
Set cmd = Nothing
Set cmd = new ADODB.Command
cmd.ActiveConne ction = cnn
cmd.CommandType = adCmdStoredProc
cmd.CommandText = my_second_proc
cmd.Execute
Set cmd = Nothing

Throwing in DTS in a VB app to solve something which works out of the
box in VB appears to be a huge overkill to me.

(And if your VB app is multi-threaded or you use asynchronous calls,
DTS would still be a huge overkill, give that implmentation of
thread-synchronization or handling of asynchronous calls is not really
rocket science, even if it goes beyond what a plain-vanilla does.)
--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #9
Fair enough :-)

Erland Sommarskog <es****@sommars kog.se> wrote in message news:<Xn******* *************** @127.0.0.1>...
Ryan (an*******@devd ex.com) writes:
My understanding of the problem was that there was a need to run two
SP's. The second SP needs to run after the first has completed. Doing
this in a series of stored procedures or an SP that runs both could
force the execution plan to determine that it's better to run the second
SP before the first (hence the problem).

I was suggesting the DTS as an option as you can make a stored procedure
'wait' until the sucess of a prior SP. In it's most simplistic terms,
this should solve the problem. It is really good at running things in
parallel as well, but this may work in this case.


That's correct, that DTS gives you a synchronization mechanism. (Hey,
that is as much I know about DTS.)

However, you can achieve the same with:

Set cmd = new ADODB.Command
cmd.ActiveConne ction = cnn
cmd.CommandType = adCmdStoredProc
cmd.CommandText = my_first_proc
cmd.Execute
Set cmd = Nothing
Set cmd = new ADODB.Command
cmd.ActiveConne ction = cnn
cmd.CommandType = adCmdStoredProc
cmd.CommandText = my_second_proc
cmd.Execute
Set cmd = Nothing

Throwing in DTS in a VB app to solve something which works out of the
box in VB appears to be a huge overkill to me.

(And if your VB app is multi-threaded or you use asynchronous calls,
DTS would still be a huge overkill, give that implmentation of
thread-synchronization or handling of asynchronous calls is not really
rocket science, even if it goes beyond what a plain-vanilla does.)

Jul 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1988
by: SQLServer007 | last post by:
25 more days until the "get it free" promotion runs out for xSQL Object (you can get it from http://www.x-sql.com) Here are just some of the great features packed in the product: - Compare SQL Server objects (databases, tables, views, stored procedures, user defined data functions etc.) accross servers. - view and print dependencies; - generate color coded scripts for any object in the database or many of them at once (many configurable...
11
10767
by: jrefactors | last post by:
I want to know the differences between SQL Server 2000 stored procedures and oracle stored procedures? Do they have different syntax? The concept should be the same that the stored procedures execute in the database server with better performance? Please advise good references for Oracle stored procedures also. thanks!!
2
2831
by: scott | last post by:
Hi, Just wondering what sort of problems and advantages people have found using stored procedures. I have an app developed in VB6 & VB.NET and our developers are starting to re-write some of the code in stored procedures (im advocating encryption of them). When deploying an application however stored procedure seem to add another level of complexity to installation. In future we also plan to have an basic ASP app with some of the...
2
9254
by: Kent Lewandowski | last post by:
hi all, Recently I wrote some stored procedures using java jdbc code (admittedly my first stab) and then tried to implement the same within java packages (for code reuse). I encountered problems doing this. I wanted to implemented a generic "Helper" class like this: /** * Helper
5
3490
by: Tim Marshall | last post by:
I was following the thread "Re: Access Treeview - Is it Safe Yet?" with interest and on reading the post describing Lauren Quantrell's SmartTree, I've run into something I don't understand: Stored Procedures. I thought stored pricedures were an Oracle/MS SQL Server thing and don't know how they work with Access Jet. I've looked at some of the help on stored procedures in A2003, but really don't understand what's going on. Can someone...
45
3442
by: John | last post by:
Hi When developing vb.bet winform apps bound to sql server datasource, is it preferable to use SELECTs or stored procedure to read and write data from/to SQL Server? Why? Thanks Regards
28
72621
by: mooreit | last post by:
The purpose for my questions is accessing these technologies from applications. I develop both applications and databases. Working with Microsoft C#.NET and Microsoft SQL Server 2000 Production and 2005 Test Environments. What is the purpose of a view if I can just copy the vode from a view and put it into a stored procedure? Should I be accessing views from stored procedures?
5
3254
by: javelin | last post by:
Can someone recommend a utility (preferably open-source) to synchronize changes across servers? I need to bring only data over in some cases, and only objects in other cases. Any ideas? Thx!
11
3454
by: peter | last post by:
I am trying to get a SQL stored procedure to use user maintained MQT implicitly which raises questions on when they are used or not used. In theory you would expect the stored procedure to pick up the MQT at the time it is bound on the creation of the static SQL. This raises the question on how you stop it or start it using a MQT as there is no option on the bind. What happens when it is rebound? What happens if the plan is made invalid...
0
9748
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11020
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10670
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10735
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10356
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9506
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7907
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
2
4143
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.