|
-
January 21st, 2004, 07:19 AM
#1
ODBC CGI Exiting Unexpectedly
I have a cgi program written in visual c++ 6 which makes multiple connections through odbc to a sql server db. this works fine when odbc is connecting to a sqlserver that is on the same machine. However, when i change the odbc to connect to a remote server and there are a number of these cgi's running, one or more of the cgi programs can sometime terminate. In the iis log file it says they have a http 502.2 status. I've put some debugs in and it seems to be getting as far as the SQLConnect stage and then something happens which kills the cgi. Any ideas why this is happening? or is there anyway I can debug this further.
here is the code I'm using to connect :
int nConnect=SQLAllocEnv( &m_hEnv );
if( nConnect==SQL_SUCCESS ) {
nConnect=SQLAllocConnect( m_hEnv,&m_hDBC );
if( nConnect==SQL_SUCCESS ) {
SQLSetConnectOption( m_hDBC,SQL_LOGIN_TIMEOUT,5 );
// Connect to the datasource.
_TUCHAR *psvSource=new _TUCHAR[ strlen( svSource )+1 ];
_TUCHAR *psvUser=new _TUCHAR;
_TUCHAR *psvPassword=new _TUCHAR;
strcpy( (char*)psvSource,svSource );
nConnect=SQLConnect( m_hDBC,psvSource,SQL_NTS,psvUser,SQL_NTS,psvPassword,SQL_NTS );
if( nConnect==SQL_SUCCESS || nConnect == SQL_SUCCESS_WITH_INFO ) {
// Now that the datasource is open, get our SQL statement handle.
nConnect=SQLAllocStmt( m_hDBC,&m_hStmt );
}
delete psvSource;
delete psvUser;
delete psvPassword;
}
else
DisplayError();
}
else
DisplayError();
-
January 21st, 2004, 07:39 AM
#2
If you are using the TCHAR.H data types, you should also use the equivalent string functions, e.g., _tcscpy, not strcpy.
psvUser and psvPassword are pointing to single characters which have not been initialised, whereas you're telling SQLConnect that they are null terminated strings (SQL_NTS).
What is the error code returned by SQLConnect? Use SQLGetDiagRec to get the associated error message. This is normally sufficient to diagnose any error.
Possibly you are running out of SQL Server connection licenses.
-
January 21st, 2004, 07:44 AM
#3
I don't get an error code from SQLConnect as the program terminates at that point! Although a lot of the time it works ok. How do I find out if I have exceded the number of SQL Server connections?
-
January 21st, 2004, 12:21 PM
#4
Use
UWORD value;
SWORD cbData;
::SQLGetInfo(m_pDatabase->m_hdbc, SQL_ACTIVE_CONNECTIONS, (PTR)&value,2,&cbData);
-
January 26th, 2004, 11:01 AM
#5
I've had time to look into this further now and have found where the problem lies. It is to do with the annonymous user I have set up in iis. This user is part of a domain i am using for the web application setup. I have no problem with the cgi's when the user is part of the domain admins NT group but when i remove the user from this group the cgi's randomly quit when trying to connect to the db. For obvious reason I do not want the annonymous user as part of the domain admins group. Can anyone tell me why this is happening?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|