473,606 Members | 2,115 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

forcing dbsqlexec to exit cleanly

I am developing a simple DB-Library program in C calling SQL Server 2000 on
windows 2003 and NT 4. I have some T-SQL code that checks for the existence
of a table and want to abort the program if the table doesn't exist. I issue
a raiserror if the table doesn't exist and then call RETURN.

I construct the string using sprintf and pass it dbfcnd and dbsqlexec. Since
the commands work, there is no error to halt the execution of the program.
Is there an easy, clean way to force dbsqlexec to fail? Do I need a stored
procedure to return an error code and then deal with that?

Thanks for any advice,

-Gary


Jul 23 '05 #1
3 2506
Hi

I have not used DB-Library but using a store procedure is usually the best
way to provide this logic. You can use an output parameter although if you
didn't want to use the return parameter.

John

"Gary" <le********@com cast.net> wrote in message
news:5d******** ************@co mcast.com...
I am developing a simple DB-Library program in C calling SQL Server 2000 on
windows 2003 and NT 4. I have some T-SQL code that checks for the
existence
of a table and want to abort the program if the table doesn't exist. I
issue
a raiserror if the table doesn't exist and then call RETURN.

I construct the string using sprintf and pass it dbfcnd and dbsqlexec.
Since
the commands work, there is no error to halt the execution of the program.
Is there an easy, clean way to force dbsqlexec to fail? Do I need a stored
procedure to return an error code and then deal with that?

Thanks for any advice,

-Gary

Jul 23 '05 #2
[posted and mailed, please reply in news]

Gary (le********@com cast.net) writes:
I am developing a simple DB-Library program in C calling SQL Server 2000
on windows 2003 and NT 4.
How come you are using DB-Library? It's a very good API, but alas Microsoft
thinks differently and has not developed DB-Library since the release of
SQL 6.5. Because of this, there are many ffeatures in SQL Server that
you don't have support for with DB-Library.

Some future version of SQL Server will not support connecting from
DB-Library at all. And already the next version of SQL Server will come
without the files to compile, link and run DB-Library.

If you have legacy software you have. But don't use DB-Library for new
development. Use ODBC or OLE DB instead.
I have some T-SQL code that checks for the existence of a table and want
to abort the program if the table doesn't exist. I issue a raiserror if
the table doesn't exist and then call RETURN.

I construct the string using sprintf and pass it dbfcnd and dbsqlexec.
Since the commands work, there is no error to halt the execution of the
program. Is there an easy, clean way to force dbsqlexec to fail? Do I
need a stored procedure to return an error code and then deal with
that?


If you insist on using DB-Library, you should set up an message
handler with dbmsghandle. This is how DB-Libarary notifies you of
SQL errors: through a callback. I believe by setting the return
status in the message handler, you can control whether the command
fails or not.

Also, after each submitted command, you should always loop with
dbresults and dbnextrow to get all result sets and rows. The message
handler may in fact no be invoked until you call dbresults, since
the message also is a result in some meaning.

--
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 23 '05 #3
Thanks for the replies. I have a legacy program that I am modifying for a
quick one-off project.

I do have a message handler installed. I solved the problem by putting the
code that checks for the table into a stored procedure and then calling it.
Since it can return a value, returning a non-zero value from the sproc does
the trick and dbsqlexec throws an error.

Thanks again,

-Gary

"Erland Sommarskog" <es****@sommars kog.se> wrote in message
news:Xn******** ************@12 7.0.0.1...
[posted and mailed, please reply in news]

Gary (le********@com cast.net) writes:
I am developing a simple DB-Library program in C calling SQL Server 2000
on windows 2003 and NT 4.
How come you are using DB-Library? It's a very good API, but alas

Microsoft thinks differently and has not developed DB-Library since the release of
SQL 6.5. Because of this, there are many ffeatures in SQL Server that
you don't have support for with DB-Library.

Some future version of SQL Server will not support connecting from
DB-Library at all. And already the next version of SQL Server will come
without the files to compile, link and run DB-Library.

If you have legacy software you have. But don't use DB-Library for new
development. Use ODBC or OLE DB instead.
I have some T-SQL code that checks for the existence of a table and want
to abort the program if the table doesn't exist. I issue a raiserror if
the table doesn't exist and then call RETURN.

I construct the string using sprintf and pass it dbfcnd and dbsqlexec.
Since the commands work, there is no error to halt the execution of the
program. Is there an easy, clean way to force dbsqlexec to fail? Do I
need a stored procedure to return an error code and then deal with
that?


If you insist on using DB-Library, you should set up an message
handler with dbmsghandle. This is how DB-Libarary notifies you of
SQL errors: through a callback. I believe by setting the return
status in the message handler, you can control whether the command
fails or not.

Also, after each submitted command, you should always loop with
dbresults and dbnextrow to get all result sets and rows. The message
handler may in fact no be invoked until you call dbresults, since
the message also is a result in some meaning.

--
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 23 '05 #4

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

Similar topics

2
1835
by: Miki Tebeka | last post by:
Hello All, If there a way a script can tell Python to enter interactive mode even if the -i command line switch was not given? I want py2exe to create an interactive session, without writing my own REPL. Thanks. --
6
2819
by: Ed L. | last post by:
I have libpq client program that repeatedly connects to a DB, queries, and then disconnects. After a seemingly random number of such successful sessions (sometimes 30, sometimes hundreds), the backend mysteriously exits after the client calls PQsetdbLogin(), and the client hangs. Any clues? Details below... Client: C program linked with 7.2.1 libpq on HP-UX B.11.00 E 9000/803. Server: PostgreSQL 7.3.2 on i686-pc-linux-gnu, compiled...
8
2508
by: Eric | last post by:
How can I quit a smartdevice application ? After I click the right-hand(up) "X" button in the Pocket PC 2002 Emulator,it seems that the smartdevice application has not been closed. (My smartdevice app has three forms. Every form has a "X" button which is close to the time information.) Why? what happened when I click the button?
15
443
by: Andrew Hayes | last post by:
Hi All I'm calling an old VB6 program from a C#.NET application using a Process component and I was wondering if the VB6 EXE can return an exit code different than 0 I know I could use the Environment.ExitCode property or even the Environment.Exit method if the called app was written using VB.NET, but I'm not looking to spend several months moving this app to .NET I'd also rather not mess about with writing exit information to a file or...
24
4845
by: Agnes | last post by:
I need to disable the exit button in the form . However, the min. and max. button need to keep it How ? Thanks a lot From Agnes
13
12482
by: Matthew | last post by:
Is there any difference between Application.Exit() and End? Are there circumstances when I should use one instead of the other? Matthew
4
3039
by: Joe Lester | last post by:
I'm getting this message on Postgres 7.4.1 (Mac OS 10.3) 2004-05-24 15:20:15 WARNING: terminating connection because of crash of another server process DETAIL: The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory. HINT: In a moment you should be able to reconnect to the database and repeat your command.
2
4982
by: Jeffrey W. Baker | last post by:
I just noticed something unexpected when using psql. I had written a shell script to bulk-load some hundreds of files into a database, and move each file to success/ or failure/ directories depending on the exit status. The problem is psql exit status differs depending on if the SQL script is provided with -c or on STDIN. Try this for example: $ echo "your mom" | psql ERROR: syntax error at or near "your" at character 1
9
23439
by: gangesmaster | last post by:
calling sys.exit() from a thread does nothing... the thread dies, but the interpreter remains. i guess the interpreter just catches and ignore the SystemExit exception... does anybody know of a way to overcome this limitation? -tomer
0
7942
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
8433
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
8429
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
8084
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,...
1
5963
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...
0
5461
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2443
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1550
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1287
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.