dbTalk Databases Forums  

dbinit(), dblogin(), how often?

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss dbinit(), dblogin(), how often? in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Bruce.
 
Posts: n/a

Default dbinit(), dblogin(), how often? - 05-31-2007 , 09:11 PM






I'm a MS SQL newbie and am programming SQL using MS DS C++ 2003.

I'm writing sql code that will reside in a shared dll, used by many
processes and many threads in those processes.

So how often do I need to call dbinit()? Only the first time the DLL is
loaded, once per new process, once per thread, or once per database open?

Same question for dblogin().

Thanks very much for any help.
Bruce.



Reply With Quote
  #2  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: dbinit(), dblogin(), how often? - 06-01-2007 , 02:53 AM






Bruce. (noone (AT) nowhere (DOT) com) writes:
Quote:
I'm a MS SQL newbie and am programming SQL using MS DS C++ 2003.

I'm writing sql code that will reside in a shared dll, used by many
processes and many threads in those processes.

So how often do I need to call dbinit()? Only the first time the DLL is
loaded, once per new process, once per thread, or once per database open?

Same question for dblogin().
Zero times. At least unless you have some very special reason to use
DB-Library at all, like the need to support a legacy application. To wit,
DB-Library is a deprecated client API, and it lacks support for new features
added since SQL7, as Microsoft has not touched it for the last 8-10 years.

The recommended choice for a C++ application are ODBC and OLE DB. Of these
the ODBC is probably a lot easier to work with.


--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx


Reply With Quote
  #3  
Old   
Bruce.
 
Posts: n/a

Default Re: dbinit(), dblogin(), how often? - 06-01-2007 , 06:29 PM



"Erland Sommarskog" <esquel (AT) sommarskog (DOT) se> wrote

Quote:
The recommended choice for a C++ application are ODBC and OLE DB. Of these
the ODBC is probably a lot easier to work with.
Not an option in this case but thanks for your reply anyway.

Bruce.




Reply With Quote
  #4  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: dbinit(), dblogin(), how often? - 06-02-2007 , 04:46 AM



Bruce. (noone (AT) nowhere (DOT) com) writes:
Quote:
"Erland Sommarskog" <esquel (AT) sommarskog (DOT) se> wrote in message
news:Xns99425A6E7696FYazorman (AT) 127 (DOT) 0.0.1...
The recommended choice for a C++ application are ODBC and OLE DB. Of
these the ODBC is probably a lot easier to work with.

Not an option in this case but thanks for your reply anyway.
I'm sorry I was not able to answer your actual question at the time, but
I did not have access to some old source code that I have. Having looked
at that one, I see that I have this:

// Init DB-Library if we are the first player.
EnterCriticalSection(&CS);
if (no_of_threads++ == 0) {
if(dbinit() == FAIL) {
croak("Can't initialize dblibrary...");
}
// Set up the error handlers once for all.
dberrhandle(err_handler);
dbmsghandle(msg_handler);
}
LeaveCriticalSection(&CS);

// Set up LOGINREC struct for this thread.
td->login = dblogin();
DBSETLUSER(td->login, NULL);
DBSETLPWD(td->login, NULL);
DBSETLHOST(td->login, getenv("COMPUTERNAME"));

That is, call dbinit() when the DLL is initiated, but call dblogin once
for each thread. Then again, I guess the reason I did it this way was
to permit different threads to use the different login information. If
all threads will use the same login details, I can't see anything else
than that it would be sufficient to call dblogin() once, since LOGINREC
appears to only hold static data.

But permit me again to point the unsuitable in using DB-Library for new
development. Or to be more blunt: it's sheer silliness. If nothing else,
it's a waste of time for your professional development. The likelyhood
that you will get the oppurtunity to reuse the knowledge of DB-Library
programming are slim, whereas learning to master the ODBC API can be very
useful.

Why would ODBC or OLE DB not be an option in your case?

--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx


Reply With Quote
  #5  
Old   
Bruce.
 
Posts: n/a

Default Re: dbinit(), dblogin(), how often? - 06-02-2007 , 12:38 PM



"Erland Sommarskog" <esquel (AT) sommarskog (DOT) se> wrote

Quote:
That is, call dbinit() when the DLL is initiated, but call dblogin once
for each thread. Then again, I guess the reason I did it this way was
to permit different threads to use the different login information. If
all threads will use the same login details, I can't see anything else
than that it would be sufficient to call dblogin() once, since LOGINREC
appears to only hold static data.
That's very interesting and helpful. Thanks for the information.

Bruce.




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.